:root {
  --bg: #14141b;
  --bg-2: #1b1b24;
  --surface: #20202b;
  --surface-2: #2a2a37;
  --border: #33334a;
  --text: #ececf3;
  --muted: #9a9ab0;
  --accent: #7c3aed;
  --accent-2: #a78bfa;
  --ok: #34d399;
  --warn: #f59e0b;
  --bad: #f87171;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: var(--bad); min-height: 1.2em; margin: 4px 0 0; }
.spacer { flex: 1; }

.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; font: inherit; white-space: nowrap;
  transition: background .15s, border-color .15s;
  text-decoration: none; display: inline-block;
}
.btn:hover { border-color: var(--accent-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #6d28d9; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: transparent; border-color: rgba(248, 113, 113, .5); color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
select, input, textarea {
  font: inherit; color: var(--text); background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-2); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }

/* login */
#login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; }
.login-card input { color: var(--text); font-size: 15px; padding: 10px 12px; }
#lCode { letter-spacing: .35em; font-size: 20px; text-align: center; font-family: Consolas, monospace; }
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.brand b { display: block; font-size: 17px; }
.brand span { color: var(--muted); font-size: 12px; }

/* home */
#home { max-width: 1200px; margin: 0 auto; padding: 0 16px 24px; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 12px 0; position: sticky; top: 0; background: var(--bg); z-index: 2; }
.small-brand { margin: 0; }
.small-brand b { font-size: 15px; }
.search { width: 200px; }
.banner { border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; font-size: 13px; }
.banner.warn { background: rgba(245, 158, 11, .12); border: 1px solid rgba(245, 158, 11, .4); color: #fcd34d; }
.pc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.group-title { grid-column: 1 / -1; margin: 10px 0 0; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.pc { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.pc.on { border-color: rgba(52, 211, 153, .35); }
.pc-head { display: flex; align-items: center; gap: 8px; }
.pc-head b { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc .meta { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc .acts { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #666; flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 6px rgba(52, 211, 153, .6); }
.dot.wait { background: var(--warn); }
.dot.bad { background: var(--bad); }
.empty { grid-column: 1 / -1; text-align: center; padding: 40px; color: var(--muted); }
.security { margin-top: 20px; }
.security h3 { margin: 0 0 6px; font-size: 15px; }
.history { width: 100%; border-collapse: collapse; margin: 8px 0 12px; font-size: 12px; }
.history th, .history td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--border); }
.history td.ok { color: var(--ok); }
.history td.bad { color: var(--bad); }

/* remote */
#remote { position: fixed; inset: 0; display: flex; flex-direction: column; background: #000; }
.rbar { display: flex; align-items: center; gap: 4px; padding: 4px 8px; background: var(--bg-2); border-bottom: 1px solid var(--border); flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.rbar::-webkit-scrollbar { display: none; }
.rbar .btn { padding: 5px 9px; font-size: 15px; }
.rbar select { padding: 4px 6px; font-size: 13px; }
.rname { white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.stats { white-space: nowrap; margin-left: 6px; }
.viewport { flex: 1; position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; background: #0b0b10; }
.viewport.scroll { overflow: auto; align-items: flex-start; justify-content: flex-start; }
#screen { display: block; outline: none; touch-action: none; image-rendering: auto; background: #111; }
.rcursor { position: absolute; width: 0; height: 0; pointer-events: none; z-index: 3;
  border-left: 7px solid #fff; border-top: 7px solid transparent; border-bottom: 7px solid transparent; transform: rotate(-30deg); transform-origin: 0 0; filter: drop-shadow(0 0 1px #000); }
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; z-index: 4; }
.overlay.hidden { display: none; }
.ov-box { background: rgba(20, 20, 27, .92); border: 1px solid var(--border); border-radius: 12px; padding: 16px 22px; text-align: center; max-width: 90%; pointer-events: auto; }
.ov-box p { margin: 0 0 10px; }
.kbd-sink { position: fixed; left: 0; bottom: 0; width: 2px; height: 2px; opacity: 0; padding: 0; border: 0; resize: none; z-index: -1; }
.menu { position: relative; }
.menu-pop { position: fixed; right: 8px; top: 44px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 6px; display: flex; flex-direction: column; min-width: 180px; z-index: 10; box-shadow: 0 8px 24px rgba(0,0,0,.5); }
.menu-pop button { background: none; border: 0; color: var(--text); text-align: left; padding: 8px 10px; border-radius: 6px; font: inherit; cursor: pointer; }
.menu-pop button:hover { background: var(--surface-2); }
.menu-pop hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; width: 100%; }
dialog { color: var(--text); max-width: 520px; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h3 { margin: 0 0 10px; }
dialog textarea { width: 100%; }
dialog .row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* toasts */
.toasts { position: fixed; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(380px, calc(100% - 24px)); }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 10px; padding: 10px 12px; box-shadow: 0 6px 20px rgba(0,0,0,.45); font-size: 13px; }
.toast.ok { border-left-color: var(--ok); }
.toast.bad { border-left-color: var(--bad); }
.toast .bar { height: 4px; background: var(--surface-2); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.toast .bar i { display: block; height: 100%; background: var(--accent-2); width: 0; transition: width .2s; }
.toast .btn { margin-top: 6px; }

@media (max-width: 640px) {
  .search { width: 120px; }
  .rname { max-width: 110px; }
  .stats { display: none; }
  .pc-grid { grid-template-columns: 1fr; }
}
