/* ======================================================================
   Reset / base
   ====================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #ffffff;
  color: #111827;
}

/* link generici */
a {
  color: #2563eb;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ======================================================================
   Layout generale (usato da radar.html)
   ====================================================================== */

.full-page {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.layout {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Topbar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
  color: #111827;
}

.divider {
  width: 1px;
  height: 24px;
  background: #e5e7eb;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.filter-item {
  font-size: 0.8rem;
  color: #4b5563;
  display: flex;
  align-items: center;
  gap: 4px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #eef2ff;
  font-size: 0.8rem;
  color: #1e3a8a;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #9ca3af;
}

/* stato connessione */
.dot.offline {
  background: #9ca3af;
}

.dot.connecting {
  background: #f97316;
}

.dot.online {
  background: #22c55e;
}

.count {
  font-weight: 600;
}

/* ======================================================================
   Input e select
   ====================================================================== */

.select,
.input-text {
  border-radius: 999px;
  border: 1px solid #d1d5db;
  padding: 4px 8px;
  font-size: 0.8rem;
  background: #ffffff;
}

.input-small {
  max-width: 150px;
}

/* ======================================================================
   Main layout
   ====================================================================== */

.main {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* riferimento per la chat overlay */
.radar-area {
  flex: 1;
  display: flex;
  align-items: flex-start;  /* prima era center */
  justify-content: center;
  padding: 12px;
  min-width: 0;
  background: #ffffff;
  position: relative;
}

/* wrapper leggermente più piccolo e staccato dall'header */
.radar-wrapper {
  width: 100%;
  max-width: 820px;         /* prima 900px: radar un po’ più piccolo */
  margin: 12px auto 16px;   /* top 12px invece di 0: spazio sotto l’header */
  padding: 8px 8px 16px;   /* AGGIUNTO */
  box-sizing: border-box;
}

/* ======================================================================
   Radar
   ====================================================================== */

.radar {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  margin: 0 auto;
  background: #f3f4f6;              /* sfondo grigio chiaro */
  border: 1px dashed #1e3a8a;       /* bordo esterno tratteggiato blu scuro */
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.15);
  overflow: hidden;
  z-index: 0;
}

/* radar dimmed quando la chat è aperta */
.radar.radar-dimmed {
  opacity: 0.35;
  filter: blur(1px);
}

/* cerchi concentrici tratteggiati blu scuro */
.radar::before,
.radar::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  border: 1px dashed #1e3a8a;
}

.radar::before {
  inset: 17.5%;
}

.radar::after {
  inset: 33%;
}

/* linee del quadrante (orizzontale + verticale) */

.radar-cross {
  position: absolute;
  pointer-events: none;
  z-index: 1;
}

.radar-cross-h {
  top: 50%;
  left: 0;
  right: 0;
  height: 0;
  border-top: 1px dashed #1e3a8a;
}

.radar-cross-v {
  left: 50%;
  top: 0;
  bottom: 0;
  width: 0;
  border-left: 1px dashed #1e3a8a;
}

/* centro TU */

.radar-center {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: #22c55e;
  color: #ffffff;
  font-size: 0.8rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.35);
  z-index: 3; /* sopra croce e puntini */
}

/* puntini degli utenti */

.radar-dot {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #2563eb; /* blu medio */
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
  z-index: 2; /* sopra le linee, sotto TU */
}

/* utente busy (impegnato in chat) */

.radar-dot.busy {
  background: #dc2626; /* rosso */
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.25);
}

/* warning geolocalizzazione */

.geo-warning {
  margin-top: 8px;
  font-size: 0.8rem;
  color: #b91c1c;
  text-align: center;
}

.hidden {
  display: none !important;
}

/* ======================================================================
   Sidebar (lista utenti + log)
   ====================================================================== */

.sidebar {
  width: 280px;
  max-width: 40%;
  border-left: 1px solid #e5e7eb;
  background: #f9fafb;
  display: flex;
  flex-direction: column;
  padding: 10px;
  gap: 8px;
}

.me-info {
  font-size: 0.8rem;
  color: #4b5563;
}

.sidebar-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin: 4px 0;
}

.user-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  overflow-y: auto;
  border-radius: 8px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
}

.user-list li {
  padding: 6px 8px;
  font-size: 0.85rem;
  border-bottom: 1px solid #f3f4f6;
  cursor: pointer;
}

.user-list li:last-child {
  border-bottom: none;
}

.user-list li:hover {
  background: #f3f4f6;
}

/* nome utente busy in rosso */

.user-list li.busy {
  color: #b91c1c;
  font-weight: 600;
}

/* area log */

.log {
  margin-top: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.7rem;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  background: #ffffff;
  padding: 4px 6px;
  height: 120px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* ======================================================================
   Pannello chat FULL overlay sul radar
   ====================================================================== */
/* Pannello chat: overlay sulla radar-area */
.chat-panel {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;

  padding: 8px;
  box-sizing: border-box;

  display: flex;
  flex-direction: column;      /* importante: non centrare, ma riempire */
  background: rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(3px);
  z-index: 5;
}

.chat-panel.hidden {
  display: none;
}

/* Card interna che contiene header, messaggi e input */
.chat-panel-inner {
  flex: 1;                     /* occupa tutto lo spazio verticale */
  width: 100%;                 /* tutta la larghezza disponibile */
  height: 100%;                /* tutta l'altezza disponibile */
  padding: 10px;
  box-sizing: border-box;

  display: flex;
  flex-direction: column;

  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.25);
}

/* header, messaggi e form restano come prima, ma adesso vivono dentro .chat-panel-inner */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: 12px;
  background: #f9fafb;
  margin-bottom: 8px;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  padding: 8px 8px;
  margin-bottom: 8px;
  border-radius: 12px;
  background: #f3f4f6;
  overflow-y: auto;
}

.chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Effetto terremoto solo sulla card interna */
@keyframes chat-shake {
  0%   { transform: translate3d(0, 0, 0); }
  10%  { transform: translate3d(-3px, -2px, 0); }
  20%  { transform: translate3d(3px, 2px, 0); }
  30%  { transform: translate3d(-3px, 2px, 0); }
  40%  { transform: translate3d(3px, -2px, 0); }
  50%  { transform: translate3d(-2px, 1px, 0); }
  60%  { transform: translate3d(2px, -1px, 0); }
  70%  { transform: translate3d(-1px, -1px, 0); }
  80%  { transform: translate3d(1px, 1px, 0); }
  90%  { transform: translate3d(-1px, 1px, 0); }
  100% { transform: translate3d(0, 0, 0); }
}

.chat-panel-inner.shake {
  animation: chat-shake 0.15s ease-in-out 20; /* ≈3s */
}


.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #111827;
  color: #f9fafb;
}

.chat-title {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-close {
  border: none;
  background: transparent;
  color: #f9fafb;
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
}

/* area messaggi occupa tutto lo spazio disponibile sopra la barra input */

.chat-messages {
  padding: 8px 10px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: #e5e7eb;
}

/* bolle messaggi stile WhatsApp */

.chat-bubble {
  position: relative;              /* per sicurezza, se ti serve in futuro */
  max-width: 80%;
  padding: 6px 10px 4px;           /* un filo meno padding sotto */
  border-radius: 16px;
  margin-bottom: 6px;
  font-size: 14px;
  line-height: 1.3;
}

/* testo del messaggio */
.chat-bubble-text {
  display: block;
}

/* orario stile WhatsApp */
.chat-bubble-time {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: #9ca3af;                  /* grigio chiaro */
  text-align: right;
}

.chat-bubble.me {
  align-self: flex-end;
  background: #dcfce7; /* verde chiaro tipo WhatsApp */
  border-bottom-right-radius: 4px;
}

.chat-bubble.them {
  align-self: flex-start;
  background: #f3f4f6;
  border-bottom-left-radius: 4px;
}

/* Barra in basso: trillo + input + invia */

.chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid #d1d5db;
  background: #f9fafb;
}

.chat-trill-btn {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid #d1d5db;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
}

.chat-trill-btn span {
  font-size: 1.1rem; /* 🔔 */
}

.chat-input {
  flex: 1;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid #d1d5db;
  font-size: 0.9rem;
}

.chat-send-btn {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: none;
  background: #22c55e;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.chat-send-btn span {
  font-size: 1.1rem; /* ✈️ */
}

/* ======================================================================
   Schermata index (nickname) – se usi un layout tipo card
   ====================================================================== */

.index-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: #ffffff;
}

.index-card {
  width: 100%;
  max-width: 420px;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
  padding: 18px 18px 16px;
}

.index-title {
  margin: 0 0 8px;
  font-size: 1.2rem;
  font-weight: 700;
  text-align: center;
}

.index-subtitle {
  margin: 0 0 12px;
  font-size: 0.9rem;
  color: #6b7280;
  text-align: center;
}

.index-form-row {
  margin-bottom: 10px;
}

.index-label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.85rem;
  color: #4b5563;
}

.index-input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid #d1d5db;
  font-size: 0.9rem;
}

.index-button {
  width: 100%;
  padding: 10px 14px;
  border-radius: 999px;
  border: none;
  background: #22c55e;
  color: #ffffff;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

/* ======================================================================
   Pagina mappa (map.html) – se usi la card
   ====================================================================== */

.map-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: #ffffff;
}

.map-card {
  width: 100%;
  max-width: 650px;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
  padding: 18px 18px 16px;
}

.card-title {
  margin: 0 0 8px;
  font-size: 1.2rem;
  font-weight: 700;
  text-align: center;
}

.subtitle {
  margin: 0 0 10px;
  font-size: 0.9rem;
  color: #6b7280;
  text-align: center;
}

#world-map {
  width: 100%;
  height: 360px;
  border-radius: 10px;
  border: 1px solid #d1d5db;
  overflow: hidden;
  background: #e5e7eb;
}

.coords-info {
  margin-top: 8px;
  font-size: 0.8rem;
  color: #4b5563;
}

.map-buttons {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.btn-primary,
.btn-secondary {
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  cursor: pointer;
}

.btn-primary {
  border: none;
  background: #22c55e;
  color: #ffffff;
  font-weight: 600;
}

.btn-secondary {
  border: 1px solid #d1d5db;
  background: #ffffff;
  color: #111827;
}

/* ======================================================================
   Responsive
   ====================================================================== */

@media (max-width: 768px) {
  .sidebar {
    display: none;
  }

  .topbar {
    flex-wrap: wrap;
    gap: 6px;
  }

  .filters {
    flex-wrap: wrap;
  }

  .chat-panel {
    inset: 0;
  }
}
