/* Unified Command — shared design tokens + component styles.
   Tactical/command-center dark UI: high density, semantic color for status,
   condensed display type for labels, monospace for coordinates/timestamps. */

:root {
  --bg: #0a0e13;
  --surface: #10161d;
  --surface-2: #161e27;
  --surface-3: #1c2733;
  --border: #232f3d;
  --border-soft: #1a2430;
  --text: #e7edf3;
  --text-dim: #8a97a8;
  --text-faint: #57687c;

  --accent: #f5a623;
  --accent-dim: #c9861a;
  --accent-bg: rgba(245, 166, 35, 0.12);

  --cyan: #38bdf8;
  --cyan-bg: rgba(56, 189, 248, 0.12);

  --green: #2ecf71;
  --green-bg: rgba(46, 207, 113, 0.14);
  --red: #ef4a5f;
  --red-bg: rgba(239, 74, 95, 0.14);
  --blue: #3b82f6;
  --purple: #a855f7;

  --radius-sm: 4px;
  --radius: 7px;
  --radius-lg: 12px;
  --shadow-panel: 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-pop: 0 4px 14px rgba(0, 0, 0, 0.55);

  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4,
.label-face {
  font-family: "Rajdhani", "Inter", sans-serif;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-wrap: balance;
}

.mono {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

a {
  color: var(--cyan);
}

button {
  font-family: inherit;
}

::selection {
  background: var(--accent-bg);
}

/* ---------- scrollbars (webkit) ---------- */
::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 5px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--surface-3);
}

/* ============================== buttons ============================== */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.btn:hover {
  background: var(--surface-3);
  border-color: var(--text-faint);
}
.btn:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 1px;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1200;
}
.btn-primary:hover {
  background: #ffb84d;
  border-color: #ffb84d;
}
.btn-danger {
  background: var(--red-bg);
  border-color: rgba(239, 74, 95, 0.4);
  color: #ff8a97;
}
.btn-danger:hover {
  background: rgba(239, 74, 95, 0.24);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--surface-2);
}
.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}
.btn-icon {
  padding: 8px;
  width: 34px;
  height: 34px;
  justify-content: center;
}
.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-toggle.is-active {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
}

/* ============================== forms ============================== */

label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 5px;
  font-weight: 600;
}
.field {
  margin-bottom: 12px;
}
input[type="text"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="url"],
select,
textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  font-size: 13.5px;
  font-family: inherit;
}
textarea {
  resize: vertical;
  min-height: 60px;
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px var(--cyan-bg);
}
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
}
.checkbox-row input {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
}
.range-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
input[type="range"] {
  accent-color: var(--accent);
  flex: 1;
}
.hint {
  font-size: 11.5px;
  color: var(--text-faint);
  margin-top: 4px;
}

/* ============================== badges/chips ============================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: none;
}
.badge-green {
  background: var(--green-bg);
  color: var(--green);
}
.badge-red {
  background: var(--red-bg);
  color: var(--red);
}
.badge-dim {
  background: var(--surface-3);
  color: var(--text-dim);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.chip input {
  display: none;
}
.chip .sw {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}
.chip.is-off {
  opacity: 0.4;
}

/* ============================== app shell ============================== */

.app {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}
.topbar .brand .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}
.topbar .spacer {
  flex: 1;
}

/* Viewer-tier sessions get the read-only badge and every edit control
   hidden — see public/js/app.js, which adds/removes this body class based
   on GET /api/session. Hiding here is UX only; the API enforces the real
   boundary regardless of what's shown. */
body.role-viewer #role-badge {
  display: inline-flex !important;
}
body.role-viewer .command-only {
  display: none !important;
}
.conn-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-dim);
  padding: 5px 10px;
  border-radius: 100px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.conn-status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--red);
}
.conn-status.is-live .dot {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

.layout {
  display: grid;
  grid-template-columns: 300px 1fr 340px;
  min-height: 0;
}
@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 270px 1fr 0;
  }
  .panel-right {
    display: none;
  }
}

.panel {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel-right {
  border-right: none;
  border-left: 1px solid var(--border);
}
.panel-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel-head h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
  margin: 0;
  flex: 1;
}
.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
}
.panel-section + .panel-section {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
}
.panel-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
  margin: 0 0 9px;
  font-weight: 700;
}

.map-wrap {
  position: relative;
  min-width: 0;
  overflow: hidden;
}
#map {
  position: absolute;
  inset: 0;
  background: #0d1319;
}

/* Leaflet dark tweaks */
.leaflet-control-zoom a {
  background: var(--surface-2) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}
.leaflet-control-attribution {
  background: rgba(10, 14, 19, 0.75) !important;
  color: var(--text-faint) !important;
}
.leaflet-control-attribution a {
  color: var(--text-dim) !important;
}
.leaflet-popup-content-wrapper {
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.leaflet-popup-tip {
  background: var(--surface-2);
}
.leaflet-popup-content {
  margin: 12px 14px;
  min-width: 190px;
}

/* ---------- floating map toolbar ---------- */
.map-toolbar {
  position: absolute;
  left: 14px;
  top: 14px;
  z-index: 15;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  box-shadow: var(--shadow-panel);
}
.map-toolbar .btn {
  justify-content: flex-start;
}
.placing-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 16;
  background: var(--accent);
  color: #1a1200;
  padding: 8px 16px;
  border-radius: 100px;
  font-weight: 700;
  font-size: 12.5px;
  box-shadow: var(--shadow-pop);
  display: none;
  align-items: center;
  gap: 10px;
}
.placing-banner.is-active {
  display: inline-flex;
}

/* ---------- roster list ---------- */
.member-item,
.drone-item,
.post-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
}
.member-item:hover,
.drone-item:hover,
.post-item:hover {
  background: var(--surface-2);
  border-color: var(--border);
}
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #04121b;
  flex: none;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border);
}
.member-meta {
  min-width: 0;
  flex: 1;
}
.member-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.member-sub {
  font-size: 11.5px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.member-actions {
  display: flex;
  gap: 4px;
  flex: none;
}

.empty-state {
  color: var(--text-faint);
  font-size: 12.5px;
  padding: 18px 4px;
  text-align: center;
}

/* ---------- filter chip groups ---------- */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ---------- drone panel ---------- */
.drone-player {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16/9;
  border: 1px solid var(--border);
}
.drone-player video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
.drone-player .placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  color: var(--text-faint);
  font-size: 12px;
  text-align: center;
  padding: 20px;
}
.drone-player .live-tag {
  position: absolute;
  top: 8px;
  left: 8px;
  background: var(--red);
  color: #fff;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 4px;
}

/* ============================== modal ============================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 9, 0.68);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-backdrop.is-open {
  display: flex;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 420px;
  max-width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-panel);
}
.modal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-soft);
}
.modal-head h3 {
  margin: 0;
  flex: 1;
  font-size: 16px;
}
.modal-body {
  padding: 16px 18px;
}
.modal-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid var(--border-soft);
}

/* ============================== login pages ============================== */

.login-shell {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 30% 20%, #131c26 0%, var(--bg) 60%);
}
.login-card {
  width: 360px;
  max-width: 90vw;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 26px;
  box-shadow: var(--shadow-panel);
}
.login-card .brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 19px;
  margin-bottom: 4px;
}
.login-card .brand .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}
.login-card p.sub {
  color: var(--text-dim);
  font-size: 12.5px;
  margin: 0 0 20px;
}
.login-error {
  background: var(--red-bg);
  color: #ff8a97;
  border: 1px solid rgba(239, 74, 95, 0.35);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 12.5px;
  margin-bottom: 14px;
  display: none;
}
.login-error.is-shown {
  display: block;
}

/* ============================== field member page ============================== */

.field-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.field-header {
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.field-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 16px 26px;
  overflow-y: auto;
}
.field-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}
.field-warning {
  background: var(--red-bg);
  color: #ff8a97;
  border: 1px solid rgba(239, 74, 95, 0.35);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  font-size: 12.5px;
  line-height: 1.5;
}
.share-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.switch {
  position: relative;
  width: 46px;
  height: 26px;
  flex: none;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.switch .track {
  position: absolute;
  inset: 0;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 100px;
  cursor: pointer;
  transition: background 0.15s;
}
.switch .track::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 2px;
  top: 2px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: transform 0.15s, background 0.15s;
}
.switch input:checked + .track {
  background: var(--green-bg);
  border-color: var(--green);
}
.switch input:checked + .track::before {
  transform: translateX(20px);
  background: var(--green);
}
.status-btns {
  display: flex;
  gap: 8px;
}
.status-btns .btn {
  flex: 1;
  justify-content: center;
}
#field-map {
  height: 220px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.coord-line {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 8px;
}

/* ============================== utility ============================== */

.row {
  display: flex;
  gap: 8px;
}
.row > * {
  flex: 1;
}
.text-faint {
  color: var(--text-faint);
}
.mt-0 {
  margin-top: 0;
}
.mb-0 {
  margin-bottom: 0;
}
