/* Значення кольорів і розмірів узяті з нативної наземки (v2/gcs/qml). */
* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: #0e0e0e;
  color: #eee;
  font: 13px/1.25 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.spacer { flex: 1; }
.view { height: 100%; }

/* Поля і кнопки */
.field {
  width: 100%;
  height: 30px;
  padding: 0 8px;
  color: #eee;
  background: #1a1a1a;
  border: 1px solid #3a3a3a;
  border-radius: 4px;
  outline: none;
}
.field::placeholder { color: #666; }
.field:focus { border-color: #4c8; }

.btn-go {
  height: 30px;
  font-size: 14px;
  color: #eee;
  background: #1e3a1e;
  border: 1px solid #4c4;
  border-radius: 4px;
}
.btn-go:hover { background: #2a5a2a; }
.btn-go:disabled { color: #666; background: #252525; border-color: #444; cursor: default; }

.dark-btn { /* DarkBtn.qml */
  height: 32px;
  padding: 0 8px;
  font-size: 12px;
  color: #ddd;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  white-space: nowrap;
}
.dark-btn:hover { color: #fff; background: #2a2a2a; border-color: #444; }
.dark-btn:disabled { color: #666; background: transparent; border-color: transparent; cursor: default; }
.btn-go-small { background: #1e3a1e; border-color: #4c4; }
.btn-go-small:hover { background: #2a5a2a; border-color: #4c4; }
.btn-go-small:disabled { background: #252525; border-color: #444; }

/* Вхід */
#view-login { display: flex; align-items: center; justify-content: center; }
.login { width: 320px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { margin: 0; font-size: 24px; font-weight: 400; color: #eee; text-align: center; }
.check { display: flex; align-items: center; gap: 6px; color: #ccc; cursor: pointer; min-height: 24px; }
.check input { position: absolute; opacity: 0; width: 0; height: 0; }
.check .box {
  flex: none; width: 18px; height: 18px; display: grid; place-items: center;
  background: #1a1a1a; border: 1px solid #3a3a3a; border-radius: 3px;
}
.check input:checked + .box { border-color: #4c8; }
.check input:checked + .box::after { content: ""; width: 10px; height: 10px; border-radius: 2px; background: #4c8; }
.login-error { margin: 0; color: #e66; min-height: 16px; overflow-wrap: anywhere; }

/* Тулбар */
.toolbar {
  position: relative;
  flex: none;
  height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 0 14px;
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
}
.video-view .toolbar { padding-left: 8px; }
.toolbar-center {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  color: #8a8a8a; font-size: 13px; font-weight: 700; pointer-events: none;
}
.toolbar-title { color: #eee; font-size: 15px; font-weight: 700; }
.net-info { color: #777; font: 11px Menlo, monospace; }
.net-info-dim { color: #666; }
.operator { color: #888; font-size: 12px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chip {
  height: 28px; padding: 0 10px; display: inline-flex; align-items: center; gap: 6px;
  color: #ddd; font-size: 12px; background: #2a2a2a; border: 1px solid #444; border-radius: 14px; white-space: nowrap;
}
.chip i { flex: none; width: 8px; height: 8px; border-radius: 50%; background: #666; }
.chip > span { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.chip.chip-bad { color: #eee; background: #3a1e1e; border-color: #c44; }
.chip.chip-bad i { background: #e66; }
.chip.chip-on { background: #1e3a1e; border-color: #4c4; }
.chip.chip-on i { background: #4c4; }
.chip.chip-pad.connected { background: #1e2e4a; border-color: #48a; }
.chip.chip-pad.connected i { background: #4cf; }
button.chip:disabled { cursor: default; }
button.chip.connected:hover { background: #25406a; }

/* Плитки */
#view-fleet { display: flex; flex-direction: column; }
.tiles-scroll { flex: 1; min-height: 0; overflow-y: auto; }
.tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 14px;
  padding: 18px;
}
.tile, .tile-add { aspect-ratio: 16 / 9; border-radius: 8px; min-width: 0; }
.tile {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 12px;
  background: #1e1e1e;
  border: 1px solid #333;
  user-select: none;
}
.tile.online { border-color: #3a5a3a; }
.tile.bound { border: 2px solid #4c4; }
.tile.clickable { cursor: pointer; }
.tile.clickable:hover { background: #252525; }
.tile.dragging { opacity: .85; }
.tile > *:not(.tile-preview):not(.tile-shade):not(.tile-actions) { position: relative; }
.tile-preview { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; pointer-events: none; }
.tile-shade {
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(rgba(0,0,0,.69), rgba(0,0,0,.25) 45%, rgba(0,0,0,.69));
}
.tile-status { display: flex; align-items: center; gap: 6px; font-size: 11px; color: #777; }
.tile-status i { width: 8px; height: 8px; border-radius: 50%; background: #555; }
.tile.online .tile-status { color: #9c9; }
.tile.online .tile-status i { background: #4c4; }
.tile.pending .tile-status { color: #cc9; }
.tile.pending .tile-status i { background: #cc9; }
.tile.bound .tile-status { color: #4c4; }
.tile.bound .tile-status i { background: #4c4; }
.tile-name {
  margin-top: 6px; color: #eee; font-size: 17px; font-weight: 700;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tile-id { color: #888; font: 10px Menlo, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-foot { margin-top: auto; display: flex; align-items: center; gap: 6px; }
.tile-hint { flex: 1; min-width: 0; font-size: 11px; color: #555; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile.clickable .tile-hint { color: #8a8; }
.tile-hint.warn, .tile.clickable .tile-hint.warn { color: #cc9; }
.tile-type { color: #667; font-size: 10px; }
.tile-time { color: #666; font-size: 10px; white-space: nowrap; }
.tile-actions { position: absolute; top: 2px; right: 2px; display: none; }
.tile:hover .tile-actions { display: flex; }
.tile-actions button {
  width: 26px; height: 26px; padding: 0; color: #888; background: transparent; border: 0; border-radius: 3px; font-size: 13px; line-height: 1;
}
.tile-actions .act-edit:hover { color: #8cf; background: #1e2e4a; }
.tile-actions .act-del { font-size: 16px; }
.tile-actions .act-del:hover { color: #e88; background: #3a1e1e; }
.tile-add {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: #666; background: transparent; border: 1px solid #333; font-size: 12px;
}
.tile-add b { font-size: 28px; font-weight: 400; line-height: 1; }
.tile-add:hover { color: #9c9; background: #1e1e1e; border-color: #4c8; }
.tile-add:hover b { color: #4c8; }

/* Екран борта */
.video-view { display: flex; flex-direction: column; }
.stage { position: relative; flex: 1; min-height: 0; background: #000; overflow: hidden; }
#video { width: 100%; height: 100%; object-fit: contain; display: block; }

.link-bar {
  position: absolute; z-index: 10; top: 10px; right: 10px; height: 22px; padding: 0 8px;
  color: #ccc; font: 11px Menlo, monospace; background: rgba(18,18,18,.69); border: 1px solid #2a2a2a; border-radius: 5px;
}
/* Жовтий: бітрейт знижено через канал. */
.link-bar.limited { color: #cc9; border-color: #6a6a3a; }
.link-bar:hover { background: rgba(38,38,38,.75); }
.menu {
  position: absolute; z-index: 11; top: 36px; right: 10px; min-width: 170px; padding: 4px 0;
  background: #1e1e1e; border: 1px solid #3a3a3a; border-radius: 4px; box-shadow: 0 4px 16px rgba(0,0,0,.5);
}
.menu button, .menu p {
  display: block; width: 100%; margin: 0; padding: 7px 12px; text-align: left; color: #ddd; background: transparent; border: 0; font-size: 13px;
}
.menu p { color: #666; }
.menu hr { margin: 4px 0; border: 0; border-top: 1px solid #333; }
.menu button:hover { background: #2a2a2a; color: #fff; }

.btn-end {
  position: absolute; z-index: 10; top: 12px; left: 50%; transform: translateX(-50%);
  width: 140px; height: 34px; display: flex; align-items: center; justify-content: center; gap: 6px;
  color: #fff; font-size: 13px; font-weight: 700; background: #6a1e1e; border: 1px solid #c44; border-radius: 17px;
}
.btn-end span { font-size: 12px; font-weight: 400; }
.btn-end:hover { background: #8a2a2a; }

.state-overlay {
  position: absolute; z-index: 5; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(100% - 60px, 460px); padding: 18px; display: flex; flex-direction: column; align-items: center; gap: 10px;
  background: rgba(20,20,20,.82); border: 1px solid #333; border-radius: 10px; text-align: center;
}
.state-overlay.failed { border-color: #a44; }
.state-icon { color: #e88; font-size: 26px; line-height: 1; }
.state-text { margin: 0; color: #bbb; font-size: 14px; white-space: pre-line; overflow-wrap: anywhere; }
.state-overlay.failed .state-text { color: #eee; }
.state-overlay.signal_lost .state-text { color: #f66; }
.state-hint { margin: 0; color: #997; font-size: 12px; white-space: pre-line; }
.state-actions { display: flex; gap: 10px; }
.spinner {
  width: 32px; height: 32px; border: 3px solid #444; border-top-color: #ccc; border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.stats {
  position: absolute; z-index: 4; top: 10px; left: 10px; margin: 0; padding: 6px 8px;
  color: #ccc; font: 11px/1.35 Menlo, monospace; background: rgba(18,18,18,.69); border: 1px solid #2a2a2a; border-radius: 5px; pointer-events: none;
}
/* Лише у вебі: браузер гальмує таймери у фоні, а натив цього не знає. */
.banner {
  position: absolute; z-index: 12; left: 0; right: 0; bottom: 0; display: grid; gap: 4px; padding: 12px;
  color: #fff; font-size: 16px; text-align: center; background: #a33;
}
.banner span { font-size: 13px; }

/* Тест контролера */
.pad-view { display: flex; flex-direction: column; gap: 16px; padding: 20px; background: #1a1a1a; overflow-y: auto; }
.pad-head { display: flex; align-items: center; flex: none; }
.btn-back { height: 32px; padding: 0 12px; color: #eee; background: #2a2a2a; border: 1px solid #555; border-radius: 4px; }
.btn-back:hover { background: #3a3a3a; }
.pad-title { font-size: 22px; color: #eee; }
.pad-state { font-size: 14px; color: #c44; max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pad-state.connected { color: #4c4; }
.pad-info { flex: none; margin: 0; color: #aaa; font-size: 13px; white-space: pre-wrap; }
.channels { flex: none; display: flex; flex-direction: column; gap: 6px; padding: 10px; background: #141414; border: 1px solid #2a2a2a; border-radius: 6px; }
.channels p { margin: 0; }
.channels-title { color: #888; font-size: 11px; }
.channels-hint { color: #776; font-size: 10px; }
.channels-grid { display: grid; grid-template-columns: repeat(4, 82px); column-gap: 14px; row-gap: 4px; font-size: 11px; }
.ch { display: flex; gap: 6px; color: #666; }
.ch b { width: 34px; font-weight: 400; color: #667; }
.ch.stick-ch b { color: #889; }
.ch.moved { color: #6c6; font-weight: 700; }
.sticks { flex: 1 1 220px; min-height: 220px; display: flex; gap: 24px; }
.stick { flex: 1; min-width: 0; margin: 0; padding: 8px; display: flex; flex-direction: column; background: #242424; border: 1px solid #444; border-radius: 6px; }
.stick figcaption { color: #888; font-size: 12px; white-space: pre; }
.stick-area { position: relative; flex: 1; min-height: 0; margin-top: 4px; overflow: hidden; }
.stick-area::before, .stick-area::after { content: ""; position: absolute; background: #333; }
.stick-area::before { left: 0; right: 0; top: 50%; height: 1px; }
.stick-area::after { top: 0; bottom: 0; left: 50%; width: 1px; }
.stick-ring { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); border: 1px solid #3a3a3a; border-radius: 50%; }
.dot-stick { position: absolute; z-index: 1; left: 50%; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%; background: #4cf; }
.stick-val { position: absolute; z-index: 1; left: 0; right: 0; bottom: 0; color: #aaa; font-size: 11px; text-align: center; white-space: pre; }
.triggers { flex: none; display: flex; gap: 12px; }
.trigger { flex: 1; height: 40px; padding: 6px; display: flex; align-items: center; gap: 8px; color: #aaa; background: #242424; border: 1px solid #444; border-radius: 4px; }
.trigger > span:first-child { width: 24px; color: #888; }
.trigger > span:last-child { width: 40px; }
.trigger div { flex: 1; height: 100%; padding: 3px 0; }
.trigger i { display: block; height: 100%; width: 0; background: #fc4; border-radius: 2px; }
.profile { flex: none; padding: 10px; display: flex; flex-direction: column; gap: 4px; background: #242424; border: 1px solid #444; border-radius: 4px; }
.profile strong { color: #ccc; font-size: 12px; }
.profile-row { display: grid; grid-template-columns: 70px 110px 110px 60px; gap: 10px; align-items: center; color: #ddd; }
.profile-head { color: #888; font-size: 11px; }
.profile select { height: 26px; color: #ddd; background: #1a1a1a; border: 1px solid #444; border-radius: 3px; }
.profile label { display: flex; align-items: center; gap: 4px; color: #ccc; font-size: 11px; }
.profile output { color: #4cf; font-family: Menlo, monospace; }
.raw-axes { flex: none; display: flex; flex-direction: column; gap: 3px; }
.raw-axes p { margin: 0; color: #888; font-size: 12px; }
.axes-flow, .buttons-flow { display: flex; flex-wrap: wrap; gap: 6px; flex: none; }
.axis { position: relative; width: 180px; height: 22px; overflow: hidden; background: #242424; border: 1px solid #444; border-radius: 3px; }
.axis i { position: absolute; top: 2px; bottom: 2px; background: #4cf; opacity: .6; }
.axis::after { content: ""; position: absolute; top: 0; bottom: 0; left: 50%; width: 1px; background: #555; }
.axis span { position: absolute; z-index: 1; left: 6px; top: 0; bottom: 0; display: flex; align-items: center; color: #ddd; font: 11px Menlo, monospace; }
.pad-btn { width: 62px; height: 30px; display: grid; place-items: center; color: #ccc; font-size: 12px; background: #333; border: 1px solid #555; border-radius: 4px; }
.pad-btn.raw { width: 44px; }
.pad-btn.down { color: #000; background: #4c4; border-color: #7f7; }

/* Діалог додавання і редагування */
.dialog { width: 360px; padding: 0; color: #eee; background: #1e1e1e; border: 1px solid #3a3a3a; border-radius: 6px; }
.dialog::backdrop { background: rgba(0,0,0,.5); }
.dialog form > header { height: 40px; display: grid; place-items: center; font-size: 14px; font-weight: 700; background: #2a2a2a; border-radius: 6px 6px 0 0; }
.dialog-body { padding: 10px 10px 14px; display: flex; flex-direction: column; gap: 10px; }
.dialog-body p { margin: 0; }
.dialog-id { color: #888; font: 11px Menlo, monospace; overflow: hidden; text-overflow: ellipsis; }
.dialog-label { margin-top: 4px !important; color: #888; font-size: 11px; }
.dialog footer { display: flex; gap: 8px; padding: 0 10px 10px; }
.pick { display: flex; gap: 6px; }
.pick button { flex: 1 1 auto; height: 30px; padding: 0 10px; color: #888; font-size: 12px; background: #1a1a1a; border: 1px solid #3a3a3a; border-radius: 4px; }
.pick button.on { color: #eee; background: #1e3a1e; border-color: #4c4; }

@media (max-width: 760px) {
  .tiles { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .toolbar-center, .net-info { display: none; }
  .sticks { gap: 8px; }
  .channels-grid { grid-template-columns: repeat(2, 82px); }
}
