/*
 * Dark, edge to edge, and built around one thing at a time: a wall of locations, or the
 * picture you are flying on. The old stylesheet had twelve colour variables and a dozen
 * hexes that ignored them, no spacing scale and no media queries; this one tokenises all
 * three so a change lands everywhere rather than in one card.
 */

:root {
  --bg: #08090c;
  --surface: #14171d;
  --surface-2: #1c212a;
  --border: #262c37;
  --text: #f2f5f8;
  --muted: #98a2b1;
  --accent: #4a9eff;
  --accent-strong: #7ab8ff;
  --on-accent: #04121f;
  --ok: #3fb950;
  --warn: #d29922;
  --danger: #f85149;
  --danger-soft: #2a1717;
  --ok-soft: #10251f;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --radius-1: 6px;
  --radius-2: 10px;
  --radius-3: 16px;
  --radius-pill: 999px;

  --text-sm: 13px;
  --text-md: 15px;
  --text-lg: 20px;
  --text-xl: 30px;

  --topbar-h: 64px;
  --shadow: 0 18px 40px rgba(0, 0, 0, .55);
  --ease: 180ms cubic-bezier(.2, .7, .3, 1);
}

* { box-sizing: border-box; }

/*
 * The browser hides [hidden] elements with `display: none`, but that comes from the user
 * agent stylesheet and any author rule beats it. Several things here are laid out with
 * flex or grid and hidden with the attribute — the login veil and the account menu among
 * them — so without this they stay on screen forever, covering the page.
 */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--text-md)/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
}

h1 { font-size: var(--text-xl); margin: 0 0 var(--space-2); letter-spacing: -.02em; }
h2 { font-size: var(--text-lg); margin: 0; letter-spacing: -.01em; }

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-5);
  background: linear-gradient(180deg, rgba(8, 9, 12, .96), rgba(8, 9, 12, .72));
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -.02em;
}

.logo {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: block;
}

.topbar-right { display: flex; align-items: center; gap: var(--space-4); position: relative; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.up { background: var(--ok); }
.dot.down { background: var(--danger); }

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2) center/cover no-repeat;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  padding: 0;
}
.avatar-large { width: 84px; height: 84px; font-size: 30px; }

.menu {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  min-width: 200px;
  padding: var(--space-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.menu-name { margin: var(--space-2); color: var(--muted); font-size: var(--text-sm); }
.menu button {
  background: none;
  border: 0;
  text-align: left;
  padding: 10px var(--space-3);
  border-radius: var(--radius-1);
  color: var(--text);
  cursor: pointer;
  font-size: var(--text-md);
}
.menu button:hover { background: var(--surface-2); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-2) 0; }

/* -------------------------------------------------------------- dashboard */

.dashboard { padding: var(--space-7) var(--space-5) var(--space-7); max-width: 1400px; margin: 0 auto; }
.dashboard-head p { color: var(--muted); margin: 0 0 var(--space-6); }

.tile-fleet {
  font: 600 12px/1.4 var(--mono, monospace);
  color: var(--accent, #4a9eff);
  margin: 2px 0 0;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-5);
}

.tile {
  border-radius: var(--radius-3);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform var(--ease), border-color var(--ease), box-shadow var(--ease);
}
.tile:hover, .tile:focus-visible {
  transform: translateY(-4px) scale(1.015);
  border-color: var(--accent);
  box-shadow: var(--shadow);
  outline: none;
}

.tile-art {
  height: 156px;
  background: linear-gradient(135deg, #1b2432, #101725);
  display: grid;
  place-items: center;
}
.tile-art-live { background: linear-gradient(135deg, #1d3350, #101d33); }
.tile-play { font-size: 34px; color: var(--accent); opacity: .85; }

/* A ready tile shows the dock's own camera. The video is scenery, not a control: clicks
   fall through it to the tile, and until frames arrive the dark ground and the play glyph
   are what shows — the same face the tile had before it was live. */
.tile-art-video {
  position: relative;
  background: linear-gradient(135deg, #1d3350, #101d33);
}
.tile-art-video video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}
.tile-art-video .tile-play {
  position: relative;
  z-index: 1;
  text-shadow: 0 2px 10px rgba(0, 0, 0, .6);
}
.tile-live {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  z-index: 1;
  font: 700 10px/1 var(--mono, monospace);
  letter-spacing: .08em;
  color: #fff;
  background: rgba(200, 40, 40, .85);
  border-radius: 4px;
  padding: 4px 6px;
}

.tile-body { padding: var(--space-4); }
.tile-body h2 { font-size: 17px; }
.tile-meta { color: var(--muted); font-size: var(--text-sm); margin: var(--space-1) 0 0; }
.tile-desc { color: var(--muted); font-size: var(--text-sm); margin: var(--space-2) 0 0; }

.tile-soon { cursor: default; opacity: .62; }
.tile-soon:hover { transform: none; border-color: var(--border); box-shadow: none; }
.tile-soon-label {
  margin: var(--space-3) 0 0;
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--warn);
}
.tile-reason { margin: var(--space-1) 0 0; font-size: var(--text-sm); color: var(--muted); }

/* ------------------------------------------------------------------- fly */

.fly { position: fixed; inset: var(--topbar-h) 0 0 0; background: #000; }

.fly-video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }

.fly-overlay {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  pointer-events: none;
}
.fly-overlay > * { pointer-events: auto; }

.fly-top {
  top: 0;
  background: linear-gradient(180deg, rgba(0, 0, 0, .72), transparent);
}
.fly-bottom {
  bottom: 0;
  flex-wrap: wrap;
  background: linear-gradient(0deg, rgba(0, 0, 0, .78), transparent);
}

.fly-where { display: flex; flex-direction: column; line-height: 1.25; }
.fly-where span { color: var(--muted); font-size: var(--text-sm); }

.fly-clock {
  margin-left: auto;
  font: 600 22px/1 var(--mono);
  padding: 10px var(--space-4);
  border-radius: var(--radius-pill);
  background: rgba(0, 0, 0, .45);
  border: 1px solid var(--border);
}
.fly-clock.low { color: var(--warn); border-color: var(--warn); }

/* The "this flight is being recorded into the map" chip. Amber on purpose: not an error,
   but a state the operator must not be able to miss. */
.fly-survey {
  margin-left: auto;
  padding: 8px var(--space-4);
  border-radius: var(--radius-pill);
  background: rgba(0, 0, 0, .45);
  border: 1px solid var(--warn);
  color: var(--warn);
  font-size: var(--text-sm);
  font-weight: 600;
  white-space: nowrap;
}
.fly-survey + .fly-clock { margin-left: var(--space-3); }

.chip {
  background: rgba(0, 0, 0, .5);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-pill);
  padding: 8px var(--space-4);
  cursor: pointer;
}
.chip:hover { background: var(--surface-2); }

.fly-stats { display: flex; gap: var(--space-5); margin: 0; }
.fly-stats dt { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .1em; }
.fly-stats dd { margin: 2px 0 0; font: 600 17px/1.2 var(--mono); }

.fly-keys { display: flex; gap: var(--space-4); flex-wrap: wrap; color: var(--muted); font-size: var(--text-sm); }
.fly-keys span { display: flex; align-items: center; gap: var(--space-1); }

.fly-speed { display: flex; align-items: center; gap: var(--space-2); margin-left: auto; font-size: var(--text-sm); color: var(--muted); }
.fly-speed input { width: 120px; }
.fly-speed output { font-family: var(--mono); color: var(--text); }

kbd {
  font: 600 11px/1 var(--mono);
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 4px 6px;
  border-radius: var(--radius-1);
  transition: background var(--ease), border-color var(--ease), color var(--ease);
}

/* A pressed key lights its on-screen twin, so the controls visibly answer the hand. */
.fly-keys kbd.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

/* R stays lit for as long as the drone is on its way back — pressed or not. */
.fly-keys kbd.lit {
  border-color: var(--warn);
  color: var(--warn);
}

/* --------------------------------------------------------------- minimap */

.fly-map {
  position: absolute;
  right: var(--space-4);
  bottom: 96px;
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  transition: width var(--ease), height var(--ease);
}

/* Read at a glance from an armslength away, over live video, while steering — which is
   why it is bigger and heavier than the interface around it, and near-opaque: the video
   behind a safety warning is texture, not information. */
.fly-banner {
  position: absolute;
  top: calc(var(--topbar-h) + var(--space-2));
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-pill);
  background: rgba(61, 45, 10, .92);
  border: 1px solid var(--warn);
  color: #f4d99a;
  font-size: var(--text-md);
  font-weight: 600;
}
.fly-banner.blocked { background: rgba(72, 18, 15, .92); border-color: var(--danger); color: #ffb3ae; }

/* The one moment this interface animates: a message that has to read as an event, not
   as a control that appeared. */
.fly-timeup {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, .45);
  /* It covers the whole view, so without this it swallows every click — including the
     one on Back, leaving the operator stuck on a screen that is telling them the flight
     is over. It is a message; nothing on it is meant to be pressed. */
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 700ms ease, visibility 700ms;
}
.fly-timeup.shown { opacity: 1; visibility: visible; }
.fly-timeup span {
  font-size: clamp(22px, 4vw, 44px);
  font-weight: 700;
  letter-spacing: -.02em;
  text-shadow: 0 4px 24px rgba(0, 0, 0, .8);
  transform: translateY(8px);
  transition: transform 700ms ease;
}
.fly-timeup.shown span { transform: none; }

@media (prefers-reduced-motion: reduce) {
  .fly-timeup, .fly-timeup span, .tile { transition: none; }
}

/* ---------------------------------------------------------------- sheets */

.sheet { padding: var(--space-6) var(--space-5) var(--space-7); max-width: 820px; margin: 0 auto; }
.sheet.wide { max-width: 1100px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  padding: var(--space-5);
  margin-top: var(--space-4);
}
.card-head { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-3); }
.card-head .hint { margin: 0; }

.row { padding: var(--space-3) 0; border-top: 1px solid var(--border); }
.row:first-child { border-top: 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: var(--space-3);
}

label { display: flex; flex-direction: column; gap: var(--space-1); font-size: var(--text-sm); color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: var(--space-2); }
label small { color: var(--muted); font-size: 11px; }

input, select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-1);
  color: var(--text);
  padding: 9px 11px;
  font: inherit;
  font-size: var(--text-sm);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-3); }

button, .button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-1);
  padding: 9px var(--space-4);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease);
}
button:hover:not(:disabled), .button:hover { background: #2a3140; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-strong); }
button.danger { border-color: #5c2b2b; color: #ff9d96; }
button.ghost { background: none; }

.hint { color: var(--muted); font-size: var(--text-sm); margin: 0 0 var(--space-2); }
.empty { color: var(--muted); font-size: var(--text-sm); }

.badge {
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  color: var(--muted);
}
.badge-ok { color: #7ee192; border-color: #1f4d2a; background: var(--ok-soft); }
.badge-warn { color: #ff9d96; border-color: #7a3a3a; background: var(--danger-soft); }

.result { font-size: var(--text-sm); }
.result.ok { color: #7ee192; }
.result.bad { color: #ff9d96; }
.warn { color: var(--warn); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: var(--space-3); margin: var(--space-3) 0 0; }
.stats dt { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.stats dd { margin: 2px 0 0; font-family: var(--mono); }

.video { width: 100%; max-height: 380px; border-radius: var(--radius-2); background: #000; display: block; }

.log { max-height: 320px; overflow: auto; font-family: var(--mono); font-size: 12px; }
.log-row { display: grid; grid-template-columns: 72px 40px 1fr; gap: var(--space-2); padding: 4px 0; border-bottom: 1px solid var(--surface-2); }
.log-time, .log-dir { color: var(--muted); }
.log-topic { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.profile-card { display: flex; flex-direction: column; gap: var(--space-4); }
.profile-picture { display: flex; align-items: center; gap: var(--space-4); }

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

.login-veil {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #16233a, var(--bg));
  padding: var(--space-4);
}
.login-card {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-3);
  padding: var(--space-6);
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 22px; margin: 0; }
.login-toggle { text-align: center; margin: 0; }
.login-toggle a { color: var(--accent); text-decoration: none; }
.login-toggle a:hover { text-decoration: underline; }

/* ----------------------------------------------------------- small screens */

@media (max-width: 720px) {
  .topbar { padding: 0 var(--space-4); }
  .dashboard, .sheet { padding-left: var(--space-4); padding-right: var(--space-4); }
  .tiles { grid-template-columns: 1fr; }
  .fly-bottom { gap: var(--space-3); }
  .fly-speed { margin-left: 0; }
  .fly-keys { display: none; }
}
