:root {
  --bg: #0f131a;
  --panel: #161d29;
  --text: #e8edf7;
  --muted: #8b98ad;
  --line: #232d3d;
  --ok: #2f9e44;
  --help: #e03131;
  --stale: #e67700;
  --ctrl: #2b7ed6;
  --danger: #8a2b2b;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(1200px 600px at 20% -10%, #1a2331 0%, var(--bg) 55%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  overflow: hidden;
}
.hidden { display: none !important; }
.spacer { flex: 1; }

button, input, select {
  font: inherit;
  color: var(--text);
}
button {
  height: 30px;
  padding: 0 11px;
  border: 0;
  border-radius: 7px;
  background: #285287;
  cursor: pointer;
  white-space: nowrap;
  font-size: 13px;
}
button:hover { background: #2f609d; }
button:disabled { opacity: .45; cursor: default; }
button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
}
button.ghost:hover { color: var(--text); border-color: #3a4a63; background: #182131; }
button.danger { background: #5b2020; color: #ffd7d7; }
button.danger:hover { background: #752727; }
button.active { background: #1f6b39; color: #eafff0; }
button.active.alt { background: #23578f; color: #e9f3ff; }
input, select {
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #0c1119;
  outline: none;
}
select { padding-right: 4px; }
input:focus, select:focus { border-color: #3a6ea5; }
label { color: var(--muted); font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; }
.error { color: #ff8787; margin: 0; min-height: 18px; font-size: 13px; }

#login {
  height: 100%;
  display: grid;
  place-items: center;
}
#login form {
  width: min(360px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}
#login h1 { margin: 0 0 4px; font-size: 24px; letter-spacing: .5px; }
#login label { display: flex; flex-direction: column; gap: 6px; }
#login button { height: 36px; }

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 44px;
  flex: 0 0 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  background: rgba(9, 13, 19, .9);
  border-bottom: 1px solid var(--line);
  z-index: 70;
}
.brand { font-weight: 700; letter-spacing: .4px; }
.conn-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--stale);
  box-shadow: 0 0 0 3px rgba(230, 119, 0, .14);
  flex: 0 0 auto;
}
.conn-dot.online { background: var(--ok); box-shadow: 0 0 0 3px rgba(47, 158, 68, .16); }
.conn-dot.offline { background: var(--help); box-shadow: 0 0 0 3px rgba(224, 49, 49, .16); }
.cast-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 28px;
  padding: 0 4px 0 10px;
  border-radius: 999px;
  background: #331b1b;
  border: 1px solid #5c2a2a;
  color: #ffc9c9;
  font-size: 12px;
  max-width: 360px;
}
.voice-chip { background: #16283b; border-color: #2b4b6d; color: #cfe6ff; }
.cast-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ff6b6b;
  animation: pulse 1.2s infinite;
  flex: 0 0 auto;
}
.voice-chip .cast-dot { background: #5aa9ff; }
@keyframes pulse { 50% { opacity: .25; } }
.cast-chip span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cast-chip button {
  height: 22px;
  padding: 0 9px;
  font-size: 12px;
  background: #5b2020;
  color: #ffd7d7;
}
.voice-chip button { background: #1f3d5c; color: #d8ecff; }
#btn-log { position: relative; }
#btn-log.new::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--help);
}
.group-select { height: 28px; max-width: 210px; min-width: 120px; font-size: 13px; }
.sound-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #0c1119;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}
.sound-toggle input { height: auto; margin: 0; }

#view-home, #view-client {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  overflow-x: auto;
  scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }
.cmd-form {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 340px;
  min-width: 220px;
  max-width: 560px;
}
.cmd-form input { flex: 1; min-width: 0; }
.cmd-form.wide {
  flex: 1 1 auto;
  max-width: none;
  min-width: 300px;
}
.client-toolbar { gap: 5px; }
.client-cmd {
  flex: 1 1 360px;
  max-width: none;
  min-width: 220px;
}
.client-name {
  font-weight: 600;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 0 1 auto;
}
.badge {
  padding: 3px 8px;
  border-radius: 999px;
  background: #263247;
  color: #c9d6ea;
  font-size: 12px;
  white-space: nowrap;
}
.help-btn.active {
  background: #6b1d1d;
  color: #ffdede;
  box-shadow: 0 0 0 2px rgba(224, 49, 49, .35);
}
.cam-index {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  font-size: 12px;
}
.cam-index select { width: 82px; height: 30px; padding: 0 4px; font-size: 12px; }

.grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 0 10px 10px;
  overflow-y: auto;
  align-content: start;
}
.tile {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #05080d;
  border: 2px solid transparent;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color .12s, transform .12s;
}
.tile:hover { border-color: #38506f; }
.tile.help { border-color: var(--help); box-shadow: inset 0 0 18px rgba(224, 49, 49, .28); }
.tile.stale { border-color: var(--stale); }
.tile.stale img { opacity: .55; }
.tile.control { border-color: var(--ctrl); }
.tile img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  background: #05080d;
}
.tile .meta {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 22px 10px 8px;
  background: linear-gradient(transparent, rgba(2, 5, 9, .88));
  font-size: 13px;
}
.tile-name, .tile-info { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-info { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.tile-os { overflow: hidden; text-overflow: ellipsis; }
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  display: inline-block;
  flex: 0 0 auto;
}
.dot.help { background: var(--help); }
.dot.stale { background: var(--stale); }
.dot.offline { background: #49566a; }
.grid-empty {
  grid-column: 1 / -1;
  padding: 30px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 10px;
}

.screen-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  margin: 0 10px 10px;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
}
.screen-wrap.help { box-shadow: inset 0 0 0 3px var(--help); }
#hd-screen {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  outline: none;
}
#hd-screen:not([src]) { opacity: 0; }
.screen-wrap.controlling #hd-screen { cursor: crosshair; }
.screen-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #5a6a80;
  font-size: 14px;
  pointer-events: none;
}
.fullscreen-exit {
  display: none;
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 3;
  opacity: .55;
}
.fullscreen-exit:hover { opacity: 1; }

body.screen-fullscreen .topbar { display: none; }
body.screen-fullscreen #view-client {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #000;
}
body.screen-fullscreen .client-toolbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  background: rgba(9, 13, 19, .94);
  border-bottom: 1px solid var(--line);
  opacity: .3;
  transition: opacity .15s;
}
body.screen-fullscreen .client-toolbar:hover { opacity: 1; }
body.screen-fullscreen #screen-wrap {
  position: absolute;
  inset: 0;
  margin: 0;
  border-radius: 0;
}
body.screen-fullscreen .fullscreen-exit { display: block; }

.log-panel {
  position: fixed;
  top: 50px;
  right: 10px;
  bottom: 10px;
  width: min(430px, calc(100vw - 20px));
  display: flex;
  flex-direction: column;
  background: #0b1018;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .5);
  z-index: 80;
}
.log-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}
.log-head button { height: 26px; }
#log {
  margin: 0;
  padding: 8px 10px;
  flex: 1;
  overflow: auto;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.drawer {
  position: fixed;
  top: 44px;
  right: 0;
  bottom: 0;
  width: min(760px, 100vw);
  display: flex;
  flex-direction: column;
  background: #0d131d;
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 50px rgba(0, 0, 0, .55);
  z-index: 65;
}
.drawer-head {
  flex: 0 0 40px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
}
.drawer-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 12px 30px;
}
.drawer-section { margin-bottom: 22px; }
.drawer-section h3 { margin: 0 0 8px; font-size: 15px; letter-spacing: .3px; }
.inline-form { display: flex; gap: 6px; margin-bottom: 8px; }
.inline-form input { flex: 1; min-width: 0; }
.filter-input { width: 100%; margin-bottom: 8px; }
.group-list, .history-list, .network-list { display: flex; flex-direction: column; gap: 6px; }
.group-row, .history-row, .network-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 8px;
  background: #121a26;
  border: 1px solid #1d2838;
  border-radius: 8px;
}
.group-row .grow, .history-row .grow { flex: 1; min-width: 0; }
.group-name, .hist-name {
  display: block;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.group-meta, .hist-meta {
  display: block;
  color: var(--muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-row { display: grid; grid-template-columns: 10px minmax(0, 1fr) 150px 96px; }
.history-row .dot { align-self: center; }
.history-row .hist-actions { display: flex; gap: 4px; justify-content: flex-end; }
.history-row select { height: 27px; font-size: 12px; max-width: 150px; }
.history-row button, .group-row button, .network-row button { height: 27px; font-size: 12px; padding: 0 8px; }
.group-row .grow { cursor: default; }
.group-row.online-filter { cursor: pointer; }
.wake-tag {
  font-size: 11px;
  color: var(--muted);
  min-width: 44px;
  text-align: right;
}
.wake-tag.wakeable { color: #8fd4a2; }
.network-row { flex-wrap: wrap; }
.network-head { display: flex; align-items: center; gap: 7px; width: 100%; }
.network-head input { flex: 1 1 180px; min-width: 100px; }
.network-cidr { color: var(--muted); font-size: 12px; white-space: nowrap; }
.network-method { height: 28px; font-size: 12px; }
.network-ssh {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
}
.network-ssh input { min-width: 0; }
.network-ssh .wide-field { grid-column: span 2; }
.network-actions { display: flex; justify-content: flex-end; width: 100%; gap: 5px; }

.cam-window {
  position: fixed;
  top: 100px;
  right: 12px;
  width: 480px;
  height: 340px;
  min-width: 260px;
  min-height: 190px;
  max-width: 96vw;
  max-height: 96vh;
  display: flex;
  flex-direction: column;
  background: #0b1018;
  border: 1px solid #2b3a4f;
  border-radius: 10px;
  overflow: hidden;
  resize: both;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
  z-index: 55;
}
.cam-window.minimized {
  height: 32px !important;
  min-height: 32px;
  resize: none;
}
.cam-window.minimized #cam-view { display: none; }
.cam-window.maximized {
  left: 10px !important;
  top: 54px !important;
  right: auto !important;
  bottom: 10px !important;
  width: auto !important;
  height: auto !important;
  max-width: none;
  max-height: none;
  resize: none;
}
.cam-head {
  height: 32px;
  flex: 0 0 32px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 6px 0 10px;
  background: #121a26;
  cursor: move;
  user-select: none;
}
.cam-head button { height: 22px; padding: 0 7px; font-size: 14px; }
.cam-status {
  color: var(--muted);
  font-size: 11px;
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#cam-view {
  flex: 1;
  min-height: 0;
  width: 100%;
  object-fit: contain;
  background: #000;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(3, 6, 10, .72);
  backdrop-filter: blur(2px);
  z-index: 85;
}
.modal-card {
  width: min(620px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid #2a374a;
  border-radius: 12px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, .6);
}
.modal-head { display: flex; align-items: center; gap: 6px; padding: 0 2px; }
#dropzone {
  border: 2px dashed #33445c;
  border-radius: 10px;
  padding: 24px 16px;
  text-align: center;
  transition: border-color .12s, background .12s;
}
#dropzone.drag { border-color: var(--ctrl); background: rgba(43, 126, 214, .1); }
.drop-title { margin: 0 0 6px; font-size: 16px; }
.drop-actions { display: flex; justify-content: center; gap: 8px; margin-top: 14px; }
.dest-field { display: flex; flex-direction: column; gap: 5px; }
.dest-field input { width: 100%; }
.transfer-actions { display: flex; align-items: center; gap: 8px; }
.progress { display: flex; flex-direction: column; gap: 6px; padding: 0 2px 2px; }
.progress .bar {
  height: 7px;
  border-radius: 999px;
  background: #0b1119;
  overflow: hidden;
}
.progress .bar span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--ctrl);
  transition: width .15s;
}
.progress .hint { overflow-wrap: anywhere; }

.terminal-card {
  width: min(960px, 100%);
  height: min(72vh, 760px);
  overflow: hidden;
}
.terminal-output {
  margin: 0;
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 10px 12px;
  background: #05080d;
  border: 1px solid #1d2838;
  border-radius: 8px;
  font-family: Consolas, "Cascadia Mono", "Courier New", monospace;
  font-size: 12.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.terminal-form { display: flex; align-items: center; gap: 7px; }
.terminal-prompt { color: #62d394; font-family: Consolas, monospace; }
.terminal-form input { flex: 1; min-width: 0; font-family: Consolas, "Cascadia Mono", monospace; }

@media (max-width: 1180px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .network-ssh { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hostbar .brand { display: none; }
}
@media (max-width: 760px) {
  .grid { grid-template-columns: 1fr; }
  .cam-window { width: calc(100vw - 24px); height: 260px; }
  .client-name { max-width: 130px; }
  .client-cmd { flex-basis: 180px; min-width: 150px; }
  .history-row { grid-template-columns: 10px minmax(0, 1fr); }
  .history-row select, .history-row .hist-actions { grid-column: 2; justify-content: flex-start; }
  .network-ssh { grid-template-columns: 1fr; }
  .network-ssh .wide-field { grid-column: auto; }
  .cast-chip { max-width: 200px; }
}
