:root {
  color-scheme: light;
  --bg: #f4f7f4;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --primary: #14532d;
  --primary-soft: #22c55e;
  --danger: #be123c;
  --danger-soft: #fb7185;
  --border: #d1d5db;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: "Tajawal", "Segoe UI", Tahoma, sans-serif;
  background:
    radial-gradient(circle at 100% 0%, #dcfce7 0%, transparent 45%),
    radial-gradient(circle at 0% 100%, #e0f2fe 0%, transparent 45%),
    var(--bg);
  color: var(--text);
  padding-top: var(--safe-top);
  padding-right: var(--safe-right);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
}

.container {
  width: min(1100px, 95vw);
  margin-inline: auto;
  padding: 1.25rem 0 2rem;
  display: grid;
  gap: 1rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem;
  box-shadow: 0 12px 30px -20px rgba(15, 23, 42, 0.4);
}

.card h1,
.card h2 {
  margin-top: 0;
}

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

.grid-form {
  display: grid;
  gap: 0.85rem;
}

.grid-form label {
  display: grid;
  gap: 0.4rem;
  font-weight: 600;
}

input,
button {
  font: inherit;
}

input {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 12px;
  padding: 0.7rem 0.8rem;
  min-height: 48px;
  font-size: 16px;
}

button {
  border: 0;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  padding: 0.7rem 0.9rem;
  min-height: 48px;
  cursor: pointer;
  font-weight: 700;
  touch-action: manipulation;
}

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

button.secondary {
  background: #334155;
}

button.danger {
  background: var(--danger);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.button-row button {
  flex: 1 1 180px;
}

.button-link {
  flex: 1 1 180px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border-radius: 12px;
  text-decoration: none;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  padding: 0.7rem 0.9rem;
}

.result-grid {
  display: grid;
  gap: 1rem;
}

.result-grid a {
  color: #0f766e;
  word-break: break-all;
}

.qr-box {
  margin-top: 0.8rem;
  display: grid;
  place-items: center;
  border: 1px dashed var(--border);
  border-radius: 14px;
  padding: 1rem;
  background: #f8fafc;
}

.qr-box img {
  max-width: 280px;
  width: 100%;
  height: auto;
}

.qr-box canvas {
  max-width: 100%;
  height: auto;
}

.hint {
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  background: #f1f5f9;
  color: #334155;
}

.status-line {
  padding: 0.6rem 0.8rem;
  background: #ecfeff;
  border: 1px solid #a5f3fc;
  border-radius: 10px;
}

.compact {
  padding: 0.9rem;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.map-card {
  padding: 0;
  overflow: hidden;
}

.map {
  height: 52vh;
  min-height: 340px;
  width: 100%;
}

.members-list,
.alerts-list {
  display: grid;
  gap: 0.6rem;
}

.member-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.7rem;
  background: #f8fafc;
}

.member-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
}

.badge {
  color: #fff;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
}

.alert-row {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.65rem;
  display: grid;
  gap: 0.25rem;
}

.alert-sos {
  border-color: var(--danger-soft);
  background: #fff1f2;
}

.alert-drift {
  border-color: #fdba74;
  background: #fff7ed;
}

.alert-offline {
  border-color: #fca5a5;
  background: #fef2f2;
}

.leaflet-touch .leaflet-bar a {
  width: 36px;
  height: 36px;
  line-height: 36px;
}

@media (max-width: 720px) {
  .container {
    width: min(100%, 100vw);
    padding: 0.5rem 0.5rem calc(0.85rem + var(--safe-bottom));
  }

  .card {
    padding: 0.85rem;
    border-radius: 14px;
  }

  h1 {
    font-size: 1.35rem;
  }

  h2 {
    font-size: 1.1rem;
  }

  .status-line,
  .hint {
    font-size: 0.95rem;
    line-height: 1.5;
  }

  .button-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  .button-row button {
    width: 100%;
    min-height: 52px;
  }

  .map {
    min-height: 300px;
    height: 54vh;
  }
}
