:root {
  --navy: #0f1b3d;
  --navy-light: #16224a;
  --blue: #2563eb;
  --green: #16a34a;
  --red: #dc2626;
  --bg: #f4f6fb;
  --border: #e3e7f0;
  --text: #1e2536;
  --muted: #7c8494;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', Roboto, sans-serif; color: var(--text); }

/* ---------- AUTH PAGE ---------- */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy) 0%, #223066 100%);
  padding: 20px;
}
.auth-wrap { width: 100%; max-width: 380px; text-align: center; }
.brand-mark { font-size: 40px; }
.auth-brand h1 { color: #fff; font-size: 28px; margin: 6px 0 4px; }
.auth-brand p { color: #b9c2e0; font-size: 13px; margin-bottom: 24px; }

.auth-card { background: #fff; border-radius: 14px; padding: 24px; box-shadow: 0 20px 40px rgba(0,0,0,.25); }
.auth-tabs { display: flex; background: var(--bg); border-radius: 10px; padding: 4px; margin-bottom: 20px; }
.tab-btn { flex: 1; border: none; background: transparent; padding: 10px; border-radius: 8px; font-weight: 600; color: var(--muted); cursor: pointer; }
.tab-btn.active { background: var(--blue); color: #fff; }

.auth-form { display: flex; flex-direction: column; text-align: left; }
.auth-form.hidden { display: none; }
.auth-form label { font-size: 12px; font-weight: 600; margin: 10px 0 4px; color: var(--muted); }
.auth-form input { padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
.auth-form input:focus { outline: none; border-color: var(--blue); }
.btn-primary { margin-top: 18px; background: var(--blue); color: #fff; border: none; padding: 12px; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 14px; }
.btn-primary:hover { background: #1d4ed8; }
.btn-primary.full { width: 100%; margin-top: 10px; }
.auth-error { color: var(--red); font-size: 12px; margin-top: 8px; min-height: 14px; }
.secure-note { color: #b9c2e0; font-size: 12px; margin-top: 18px; }

/* ---------- DASHBOARD ---------- */
.dash-body { display: flex; min-height: 100vh; background: var(--bg); }

.sidebar {
  width: 220px; background: var(--navy); color: #fff;
  display: flex; flex-direction: column; padding: 18px 14px; flex-shrink: 0;
}
.side-brand { font-size: 18px; font-weight: 700; margin-bottom: 24px; }
.nav-item { display: block; color: #c6cde6; text-decoration: none; padding: 10px 12px; border-radius: 8px; margin-bottom: 4px; font-size: 14px; }
.nav-item:hover, .nav-item.active { background: var(--navy-light); color: #fff; }
.side-footer { margin-top: auto; }
.btn-outline { width: 100%; background: transparent; border: 1px solid #3a4573; color: #fff; padding: 10px; border-radius: 8px; cursor: pointer; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 16px 24px; background: #fff; border-bottom: 1px solid var(--border); }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.icon-btn { position: relative; background: none; border: none; font-size: 18px; cursor: pointer; }
.badge { position: absolute; top: -4px; right: -8px; background: var(--red); color: #fff; font-size: 10px; padding: 1px 5px; border-radius: 10px; }
.user-chip { background: var(--bg); padding: 6px 12px; border-radius: 20px; font-size: 13px; font-weight: 600; }

.notif-wrap { position: relative; }
.notif-dropdown { position: absolute; right: 0; top: 30px; width: 300px; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.12); padding: 14px; z-index: 50; }
.notif-dropdown.hidden { display: none; }
.notif-item { display: flex; flex-direction: column; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.notif-actions { display: flex; gap: 8px; }
.btn-accept { background: var(--green); color: #fff; border: none; padding: 6px 10px; border-radius: 6px; font-size: 12px; cursor: pointer; }
.btn-decline { background: var(--red); color: #fff; border: none; padding: 6px 10px; border-radius: 6px; font-size: 12px; cursor: pointer; }

.content { flex: 1; display: flex; gap: 18px; padding: 20px 24px; overflow: auto; }
.map-card { flex: 1; background: #fff; border-radius: 12px; border: 1px solid var(--border); overflow: hidden; min-height: 500px; }
#map { width: 100%; height: 100%; min-height: 500px; }

.side-cards { width: 300px; flex-shrink: 0; display: flex; flex-direction: column; gap: 16px; }
.card { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.card h3 { font-size: 14px; margin-bottom: 6px; }
.card input { width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 8px; margin-top: 8px; font-size: 13px; }
.muted { color: var(--muted); font-size: 12px; }
.hint { font-size: 12px; margin-top: 6px; color: var(--muted); }
.hidden { display: none !important; }

.tracked-item { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; font-size: 13px; border-bottom: 1px solid var(--border); }
.dot-online { width: 8px; height: 8px; border-radius: 50%; background: var(--green); display: inline-block; }



/* ---------- RESPONSIVE / MOBILE ---------- */

/* Prevent horizontal overflow */
html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

button, input {
  max-width: 100%;
}

@media (max-width: 1024px) {
  .sidebar {
    width: 190px;
  }

  .content {
    gap: 12px;
    padding: 14px;
  }

  .side-cards {
    width: 280px;
  }
}

/* Tablet + Mobile */
@media (max-width: 768px) {
  .dash-body {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
  }

  /* Compact top navigation */
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 1000;
    width: 100%;
    height: auto;
    min-height: 58px;
    flex-direction: row;
    align-items: center;
    padding: 8px 10px;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .side-brand {
    margin: 0;
    font-size: 15px;
    white-space: nowrap;
    flex: 0 0 auto;
  }

  .sidebar nav {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1 1 auto;
    min-width: max-content;
  }

  .nav-item {
    margin: 0;
    padding: 8px 10px;
    font-size: 12px;
    white-space: nowrap;
  }

  .side-footer {
    margin: 0;
    flex: 0 0 auto;
  }

  .btn-outline {
    width: auto;
    min-width: 70px;
    padding: 8px 10px;
    font-size: 11px;
  }

  .main {
    width: 100%;
    min-width: 0;
  }

  .topbar {
    position: sticky;
    top: 58px;
    z-index: 900;
    padding: 10px 12px;
    min-height: 52px;
  }

  .topbar h2 {
    font-size: 16px;
  }

  .topbar-right {
    gap: 8px;
  }

  .user-chip {
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 5px 9px;
    font-size: 11px;
  }

  .content {
    width: 100%;
    flex-direction: column;
    padding: 10px;
    gap: 10px;
    overflow: visible;
  }

  .map-card {
    width: 100%;
    min-height: 55dvh;
    order: 1;
    border-radius: 10px;
  }

  #map {
    width: 100%;
    height: 55dvh;
    min-height: 320px;
  }

  .side-cards {
    width: 100%;
    order: 2;
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .card {
    width: 100%;
    padding: 13px;
    border-radius: 10px;
  }

  .card h3 {
    font-size: 14px;
  }

  .card input {
    min-height: 44px;
    font-size: 16px; /* prevents iOS zoom */
  }

  .btn-primary {
    min-height: 44px;
    font-size: 14px;
  }

  .tracked-item {
    min-height: 48px;
    padding: 9px 2px;
  }

  .notif-dropdown {
    position: fixed;
    top: 62px;
    left: 10px;
    right: 10px;
    width: auto;
    max-height: 70dvh;
    overflow-y: auto;
  }

  .tracking-banner {
    position: absolute;
    left: 8px;
    right: 8px;
    top: 8px;
    z-index: 500;
    margin: 0;
    font-size: 11px;
    padding: 8px 10px;
  }
}

/* Small phones */
@media (max-width: 480px) {
  .sidebar {
    flex-wrap: wrap;
    justify-content: space-between;
  }

  .side-brand {
    width: auto;
    font-size: 14px;
  }

  .sidebar nav {
    order: 3;
    width: 100%;
    flex-basis: 100%;
    justify-content: center;
  }

  .nav-item {
    flex: 1;
    text-align: center;
  }

  .topbar {
    top: 98px;
    padding: 9px 10px;
  }

  .topbar h2 {
    font-size: 14px;
  }

  .user-chip {
    max-width: 95px;
  }

  .content {
    padding: 8px;
  }

  .map-card {
    min-height: 52dvh;
  }

  #map {
    height: 52dvh;
    min-height: 280px;
  }

  .tracking-banner {
    font-size: 10px;
  }

  .tracking-banner .close-banner {
    font-size: 18px;
  }

  .notif-dropdown {
    top: 56px;
    left: 8px;
    right: 8px;
  }
}

/* Very small phones */
@media (max-width: 360px) {
  .side-brand {
    font-size: 13px;
  }

  .btn-outline {
    min-width: 62px;
    padding: 7px 8px;
    font-size: 10px;
  }

  .nav-item {
    font-size: 11px;
    padding: 7px 6px;
  }

  .topbar h2 {
    font-size: 13px;
  }

  #map {
    min-height: 250px;
  }
}

/* Touch-friendly Leaflet controls */
@media (pointer: coarse) {
  .leaflet-control-zoom a {
    width: 42px;
    height: 42px;
    line-height: 42px;
    font-size: 20px;
  }

  .leaflet-control-attribution {
    font-size: 9px;
  }
}

/* Login / signup responsive improvements */
@media (max-width: 480px) {
  .auth-body {
    min-height: 100dvh;
    padding: 14px;
  }

  .auth-wrap {
    width: 100%;
    max-width: 100%;
  }

  .auth-brand h1 {
    font-size: 25px;
  }

  .auth-brand p {
    font-size: 12px;
    margin-bottom: 18px;
  }

  .auth-card {
    width: 100%;
    padding: 18px;
    border-radius: 12px;
  }

  .auth-form input {
    min-height: 44px;
    font-size: 16px;
  }

  .tab-btn {
    min-height: 42px;
  }

  .secure-note {
    font-size: 11px;
  }
}
