/* [hidden] must always win over display rules */
[hidden] { display: none !important; }

:root {
  color-scheme: dark;
  --bg: #070d16;
  --bg-soft: #0c1522;
  --panel: #0f1c2c;
  --panel-2: #132337;
  --line: #223850;
  --text: #e6f0fa;
  --muted: #8aa2b8;
  --accent: #37d2c4;
  --accent-2: #2b9fd8;
  --danger: #ff4d57;
  --warn: #ffb020;
  --ok: #4ade80;
  --radius: 14px;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  --sans: "Segoe UI", Inter, system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: radial-gradient(1200px 700px at 15% -10%, #10273b 0%, var(--bg) 55%);
  color: var(--text);
  font-family: var(--sans);
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  padding: 0.65rem 0.9rem;
  transition: filter 120ms ease, border-color 120ms ease, transform 80ms ease;
}

button:hover:not(:disabled) {
  filter: brightness(1.12);
  border-color: #335a7a;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

button.primary {
  background: linear-gradient(180deg, #2ec3b7, #1d9e96);
  border-color: #2ec3b7;
  color: #041412;
  font-weight: 700;
}

button.warn {
  background: #3a2a08;
  border-color: #8a6412;
  color: #ffd166;
  font-weight: 600;
}

button.ghost {
  background: transparent;
}

button.small {
  padding: 0.45rem 0.65rem;
  font-size: 0.82rem;
}

button.danger-text {
  color: #ff9aa0;
}

.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.muted {
  color: var(--muted);
}

.error {
  min-height: 1.2em;
  color: #ff8b91;
  font-size: 0.85rem;
  margin: 0;
}

.hint {
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.45;
  margin: 0.4rem 0 0;
}

code {
  font-family: var(--mono);
  color: #bfe9e5;
}

/* ---------------- login ---------------- */

.login-view {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 2rem;
}

.login-card {
  width: min(380px, 100%);
  background: linear-gradient(180deg, rgba(19, 35, 55, 0.96), rgba(10, 20, 32, 0.96));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 2rem;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
  display: grid;
  gap: 0.9rem;
}

.brand-mark {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.brand-mark span {
  color: var(--accent);
}

.brand-mark.small {
  font-size: 1.25rem;
}

.login-card label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}

input[type="text"],
input[type="password"],
input[type="url"],
select {
  width: 100%;
  background: #08121e;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0.6rem 0.7rem;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(43, 159, 216, 0.14);
}

/* ---------------- app shell ---------------- */

.app-view {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1.1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 13, 22, 0.72);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--line);
  background: #0a1521;
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  font-size: 0.76rem;
  color: var(--muted);
  white-space: nowrap;
}

.pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.pill.online {
  color: var(--ok);
  border-color: rgba(74, 222, 128, 0.35);
}

.pill.offline {
  color: #ff7b82;
  border-color: rgba(255, 77, 87, 0.3);
}

.pill.lease {
  color: var(--accent);
  border-color: rgba(55, 210, 196, 0.4);
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 330px;
  gap: 1rem;
  padding: 1rem;
  align-items: start;
}

.panel {
  background: linear-gradient(180deg, rgba(19, 35, 55, 0.9), rgba(10, 20, 32, 0.9));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
}

.panel h2,
.panel h3 {
  margin: 0 0 0.7rem;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.divider {
  height: 1px;
  background: var(--line);
  margin: 0.9rem 0;
}

/* ---------------- vehicles ---------------- */

.vehicle-list {
  display: grid;
  gap: 0.5rem;
}

.vehicle {
  width: 100%;
  text-align: left;
  background: #0b1725;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem;
  display: grid;
  gap: 0.2rem;
}

.vehicle.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(55, 210, 196, 0.25) inset;
}

.vehicle .name {
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.vehicle .meta {
  font-size: 0.74rem;
  color: var(--muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #52657a;
  align-self: center;
}

.dot.online {
  background: var(--ok);
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.7);
}

.session-info {
  font-size: 0.8rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.pilot-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
  font-size: 0.82rem;
}

.pilot-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  border-radius: 7px;
  background: #0b1725;
}

.pilot-list .controller {
  color: var(--accent);
}

/* ---------------- stage ---------------- */

.stage {
  display: grid;
  gap: 1rem;
  min-width: 0;
}

.video-shell {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  background: #04080d;
}

.video-shell video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
}

.video-shell video.live {
  display: block;
}

.video-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 0.3rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.video-empty-icon {
  font-size: 2.4rem;
  color: #24405c;
}

.video-shell video.live ~ .video-empty {
  display: none;
}

.video-hud {
  position: absolute;
  left: 0.75rem;
  top: 0.75rem;
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.hud-chip {
  background: rgba(4, 10, 16, 0.7);
  border: 1px solid rgba(138, 162, 184, 0.3);
  border-radius: 6px;
  padding: 0.2rem 0.45rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
}

.hud-chip.armed {
  color: #ffd166;
  border-color: rgba(255, 209, 102, 0.45);
}

.hud-chip.estop {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
  animation: pulse 0.9s infinite alternate;
}

@keyframes pulse {
  from { opacity: 1; }
  to { opacity: 0.55; }
}

.telemetry-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.7rem;
}

.telemetry-card {
  background: linear-gradient(180deg, rgba(19, 35, 55, 0.9), rgba(10, 20, 32, 0.9));
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 0.7rem 0.8rem;
  display: grid;
  gap: 0.3rem;
}

.telemetry-card .label {
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.telemetry-card .value {
  font-size: 1.05rem;
}

/* ---------------- controls ---------------- */

.control-panel {
  display: grid;
  gap: 0.7rem;
  position: sticky;
  top: 4.6rem;
}

.estop {
  width: 100%;
  padding: 1.05rem;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: #fff;
  background: radial-gradient(circle at 50% 20%, #ff6b73, #c81e2b 70%);
  border: 1px solid #ff8b91;
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(200, 30, 43, 0.35);
}

.lease-row,
.arm-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.lease-row .pill {
  flex: 1;
}

.arm-row button {
  flex: 1;
}

.mode-select {
  display: grid;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.pad-wrap {
  display: grid;
  gap: 0.5rem;
  justify-items: center;
}

.pad {
  width: 190px;
  height: 190px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: radial-gradient(circle, #102338 0%, #08131f 72%);
  position: relative;
  touch-action: none;
  user-select: none;
  box-shadow: inset 0 0 40px rgba(43, 159, 216, 0.12);
}

.pad::after {
  content: "";
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  border: 1px dashed rgba(138, 162, 184, 0.18);
}

.pad-cross::before,
.pad-cross::after {
  content: "";
  position: absolute;
  background: rgba(138, 162, 184, 0.14);
}

.pad-cross::before {
  left: 50%;
  top: 8%;
  bottom: 8%;
  width: 1px;
}

.pad-cross::after {
  top: 50%;
  left: 8%;
  right: 8%;
  height: 1px;
}

.pad-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 62px;
  height: 62px;
  margin: -31px 0 0 -31px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #4fe3d5, #1d8f88 70%);
  border: 1px solid #7af0e5;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
  transition: transform 60ms linear;
  pointer-events: none;
}

.pad.active .pad-knob {
  background: radial-gradient(circle at 35% 30%, #ffe08a, #ff9f1c 70%);
  border-color: #ffd166;
}

.pad-caption {
  font-size: 0.72rem;
  text-align: center;
  line-height: 1.4;
}

.vertical {
  display: grid;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.vertical input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.control-status {
  display: grid;
  gap: 0.4rem;
  font-size: 0.78rem;
}

.control-status > div {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

/* ---------------- toasts ---------------- */

.toasts {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  display: grid;
  gap: 0.5rem;
  z-index: 50;
  max-width: min(360px, calc(100vw - 2rem));
}

.toast {
  background: #101f30;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent-2);
  border-radius: 9px;
  padding: 0.6rem 0.8rem;
  font-size: 0.82rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  animation: toast-in 140ms ease-out;
}

.toast.error {
  border-left-color: var(--danger);
}

.toast.warn {
  border-left-color: var(--warn);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------------- responsive ---------------- */

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .control-panel {
    grid-column: 1 / -1;
    position: static;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .control-panel .estop,
  .control-panel .mode-select,
  .control-panel .pad-wrap,
  .control-panel .vertical {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .workspace {
    grid-template-columns: 1fr;
    padding: 0.7rem;
  }

  .topbar {
    flex-wrap: wrap;
  }

  .topbar-status {
    order: 3;
    width: 100%;
    margin-left: 0;
  }

  .telemetry-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .control-panel {
    grid-template-columns: 1fr;
  }

  .control-panel .estop {
    position: sticky;
    bottom: 0.7rem;
    z-index: 5;
  }
}
