:root {
  --blue: #1a4f8a;
  --blue-dark: #123a66;
  --bg: #f4f6f9;
  --card: #ffffff;
  --border: #dde3ea;
  --text: #1f2937;
  --muted: #6b7280;
  --danger: #c0392b;
  --dsp: #2563eb;
  --dss: #059669;
  --sel: #7c3aed;
  --mm: #b45309;
  --admin: #1f2937;
  --tl: #b91c1c;
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  background: var(--blue-dark);
  color: white;
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.topbar .brand { font-weight: 600; font-size: 1.1rem; }
.topbar .userinfo { font-size: 0.9rem; display: flex; align-items: center; gap: 12px; }

.container {
  max-width: 900px;
  margin: 40px auto;
  padding: 0 16px;
}

.center-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.card + .card { margin-top: 20px; }

h1, h2, h3 { margin-top: 0; }

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--muted);
}

input, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  margin-bottom: 16px;
}

button {
  background: var(--blue);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: 600;
}

button:hover { background: var(--blue-dark); }
button.secondary { background: var(--muted); }
button.danger { background: var(--danger); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.error-msg {
  background: #fdecea;
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 0.9rem;
  margin-bottom: 16px;
  display: none;
}

.error-msg.show { display: block; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  color: white;
}

.badge.MM { background: var(--mm); }
.badge.ADMIN { background: var(--admin); }
.badge.SEL { background: var(--sel); }
.badge.DSP { background: var(--dsp); }
.badge.DSS { background: var(--dss); }
.badge.TL { background: var(--tl); }
.badge.none { background: var(--muted); }

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }

.team-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 14px;
}

.team-card h3 { margin-bottom: 10px; }

.member-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
}

.inline-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin-top: 12px;
}

.inline-form > div { flex: 1; margin-bottom: 0; }
.inline-form label { margin-bottom: 6px; }
.inline-form input, .inline-form select { margin-bottom: 0; }

.user-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.user-row-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.user-row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

#usersList .user-row-actions button,
#teamsList .user-row-actions button {
  padding: 6px 10px;
  font-size: 0.8rem;
}

.mission-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  margin: 8px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
}
.mission-row:hover {
  background: var(--bg);
  border-color: var(--blue);
}

.tracker-link {
  display: inline-block;
  margin-top: 10px;
  color: var(--blue);
  font-weight: 600;
  text-decoration: none;
}

.muted { color: var(--muted); font-size: 0.85rem; }

.my-gps-status.active { color: var(--dsp); font-weight: 600; }
.my-gps-status.error { color: var(--danger); font-weight: 600; }

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.actions-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.link-name {
  background: none;
  border: none;
  color: var(--blue);
  font-weight: 600;
  padding: 0;
  text-align: left;
  text-decoration: underline;
  cursor: pointer;
  font-size: inherit;
}
.link-name:hover { background: none; color: var(--blue-dark); }

/* Modale con z-index ridotto per non sovrapporsi ai droni */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 2000;
}
.modal-overlay.show { display: flex; }

.modal-box {
  background: var(--card);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  padding: 6px;
  cursor: pointer;
}
.modal-close:hover { background: none; color: var(--text); }

.profile-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.profile-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.profile-field-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--muted);
}

.profile-field-value {
  font-size: 0.95rem;
  word-break: break-word;
}

/* Stili aggiuntivi per la finestra video del drone (ridimensionabile e draggabile) */
.video-window {
  position: fixed;
  z-index: 3000;
  width: 320px;
  background: rgba(0,0,0,0.92);
  border: 2px solid #555;
  border-radius: 8px;
  overflow: hidden;
  resize: both;
  min-width: 250px;
  min-height: 180px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.6);
}

.video-window.live {
  border-color: #cc0000;
}

.vw-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #1a1a1a;
  padding: 6px 10px;
  cursor: move;
  user-select: none;
}

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

/* ── Mobile ─────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .container { margin: 16px auto; padding: 0 10px; }
  .card { padding: 16px; }
  .topbar { padding: 12px 14px; flex-wrap: wrap; gap: 8px; }

  .inline-form { flex-direction: column; align-items: stretch; }
  .inline-form button { width: 100%; }

  table { font-size: 0.82rem; }
  th, td { padding: 8px 6px; }

  .actions-cell { flex-direction: column; align-items: stretch; }
  .actions-cell button { width: 100%; }

  .user-row { flex-direction: column; align-items: stretch; }
  .user-row-actions { flex-direction: column; justify-content: stretch; }
  .user-row-actions button { width: 100%; }

  .member-row { flex-direction: column; align-items: stretch; gap: 8px; }

  .modal-box { padding: 18px; max-width: 100%; }
}