* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  /* Prevent overscroll bounce on iOS */
  overflow: hidden;
}

/* Navigation */
#nav {
  background: #16213e;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid #0f3460;
  min-height: 44px;
}

.nav-brand {
  font-size: 1.1rem;
  font-weight: bold;
  color: #e94560;
  text-decoration: none;
}

.nav-links {
  display: flex;
  gap: 12px;
  margin-left: auto;
}

.nav-links a {
  color: #aaa;
  text-decoration: none;
  font-size: 0.9rem;
  padding: 4px 8px;
  border-radius: 4px;
}

.nav-links a:hover { color: #e0e0e0; }
.nav-links a:active { color: #e94560; }
.nav-links a.active { color: #e94560; }

/* Hamburger button — hidden on desktop */
.nav-hamburger {
  display: none;
  background: none;
  border: none;
  color: #aaa;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px;
  margin-left: auto;
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
}

.nav-hamburger:active { color: #e94560; }

/* Messages */
#messages {
  padding: 8px 16px;
}

.message {
  padding: 8px 12px;
  margin-bottom: 4px;
  border-radius: 4px;
  font-size: 0.9rem;
}

.message-success { background: #1a4a2e; color: #2ecc71; }
.message-error { background: #4a1a1a; color: #e74c3c; }
.message-warning { background: #4a3a1a; color: #f1c40f; }

/* Content */
#content {
  flex: 1;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

/* Feed panel — desktop sidebar */
#feed-panel {
  width: 25%;
  min-width: 240px;
  background: #1a1a2e;
  border-right: 1px solid #0f3460;
  overflow-y: auto;
}

.feed-entry {
  padding: 10px 12px;
  border-bottom: 1px solid #0f3460;
  border-left: 3px solid #3498db;
  cursor: pointer;
  transition: background 0.15s;
}

.feed-entry:hover {
  background: #16213e;
}

.feed-entry:active {
  background: #1a2d50;
}

.feed-entry .feed-event {
  font-weight: bold;
  font-size: 0.85rem;
  color: #e0e0e0;
}

.feed-entry .feed-location {
  font-size: 0.75rem;
  color: #888;
  margin-top: 2px;
}

.feed-entry .feed-time {
  font-size: 0.7rem;
  color: #666;
  margin-top: 2px;
}

@keyframes feed-flash {
  from { background: rgba(233, 69, 96, 0.25); }
  to   { background: transparent; }
}

.feed-entry.flash {
  animation: feed-flash 1s ease-out;
}

.feed-entry.muted {
  opacity: 0.5;
}

/* Map wrapper */
#map-wrap {
  flex: 1;
  position: relative;
}

/* Map page */
#map { width: 100%; height: 100%; }

.leaflet-popup-content-wrapper {
  background: #16213e;
  color: #e0e0e0;
  border: 1px solid #0f3460;
}
.leaflet-popup-tip { background: #16213e; }
.popup-title { font-weight: bold; font-size: 1rem; margin-bottom: 6px; }
.popup-title-link { color: #e94560; text-decoration: none; }
.popup-title-link:hover { text-decoration: underline; }
.popup-row { font-size: 0.8rem; margin: 2px 0; color: #bbb; }
.popup-row span { color: #e0e0e0; }

/* CAP detail modal */
#cap-detail-modal .cap-detail-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 2000;
}
#cap-detail-modal .cap-detail-content {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2001;
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 8px;
  width: 90%;
  max-width: 700px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
#cap-detail-modal .cap-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #0f3460;
  font-weight: bold;
  font-size: 0.95rem;
  color: #e94560;
}
#cap-detail-modal .cap-detail-header button {
  background: none;
  border: none;
  color: #aaa;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 8px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#cap-detail-modal .cap-detail-header button:hover { color: #e0e0e0; }
#cap-detail-modal .cap-detail-header button:active { color: #e94560; }
#cap-detail-modal pre {
  padding: 16px;
  overflow: auto;
  flex: 1;
  font-size: 0.75rem;
  line-height: 1.5;
  color: #c0c0c0;
  white-space: pre-wrap;
  word-break: break-word;
}

.legend {
  background: #16213e;
  border: 1px solid #0f3460;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 3px 0;
  line-height: 1.4;
}

/* APRS sprite icon on map — remove Leaflet's default white box */
.aprs-icon {
  background: none !important;
  border: none !important;
}

/* Map status bar */
#map-status {
  position: absolute;
  top: 10px;
  right: 16px;
  z-index: 1000;
  display: flex;
  gap: 12px;
  align-items: center;
}

#count {
  font-size: 0.85rem;
  background: #0f3460;
  padding: 3px 10px;
  border-radius: 12px;
}

#status {
  font-size: 0.8rem;
  color: #aaa;
  display: flex;
  align-items: center;
  gap: 6px;
}

.spinner {
  width: 12px;
  height: 12px;
  border: 2px solid rgba(170,170,170,0.3);
  border-top-color: #aaa;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner.error {
  border-color: rgba(231,76,60,0.3);
  border-top-color: #e74c3c;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#last-update {
  font-size: 0.75rem;
  color: #666;
  background: rgba(15,52,96,0.6);
  padding: 2px 8px;
  border-radius: 10px;
}

#sound-toggle {
  font-size: 0.75rem;
  color: #aaa;
  background: rgba(15,52,96,0.6);
  border: 1px solid rgba(170,170,170,0.2);
  padding: 3px 10px;
  border-radius: 12px;
  cursor: pointer;
  font-family: inherit;
}
#sound-toggle:hover { color: #fff; border-color: rgba(170,170,170,0.5); }
#sound-toggle.on { color: #2ecc71; border-color: rgba(46,204,113,0.4); }

/* Mobile-only elements — hidden on desktop */
#drawer-toggle {
  display: none;
}

#map-bottom-bar {
  display: none;
}

#mobile-legend-btn {
  display: none;
}

#mobile-legend-popup {
  display: none;
}

/* Forms */
.form-container {
  max-width: 700px;
  margin: 24px auto;
  padding: 0 16px;
  overflow-y: auto;
}

.form-container h2 {
  color: #e94560;
  margin-bottom: 16px;
  font-size: 1.3rem;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.9rem;
  color: #aaa;
}

.form-input, .form-select, input[type="text"], input[type="email"],
input[type="password"], input[type="number"], select {
  width: 100%;
  padding: 8px 12px;
  background: #0f3460;
  border: 1px solid #1a3a6e;
  border-radius: 4px;
  color: #e0e0e0;
  font-size: 0.9rem;
}

.form-input:focus, .form-select:focus, input:focus, select:focus {
  outline: none;
  border-color: #e94560;
}

input[type="checkbox"] {
  width: auto;
  margin-right: 8px;
}

.btn {
  display: inline-block;
  padding: 8px 20px;
  background: #e94560;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  text-decoration: none;
}

.btn:hover { background: #c73e54; }
.btn:active { background: #b03348; }

/* Feed subscription table */
.feed-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
}

.feed-table th, .feed-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid #0f3460;
}

.feed-table th {
  color: #aaa;
  font-size: 0.8rem;
  text-transform: uppercase;
}

/* Feed subscription cards */
.feed-card {
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
}

.feed-card-header {
  font-weight: bold;
  font-size: 1rem;
  color: #e0e0e0;
  margin-bottom: 10px;
}

.feed-card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #0f3460;
  font-size: 0.9rem;
}

.feed-card-row:last-child {
  border-bottom: none;
}

.feed-card-label {
  color: #aaa;
}

.feed-card-row input[type="text"],
.feed-card-row select {
  width: 60%;
}

/* Admin pages */
.admin-nav {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid #0f3460;
}
.admin-nav a {
  color: #aaa;
  text-decoration: none;
  font-size: 0.9rem;
}
.admin-nav a.active { color: #e94560; }
.admin-nav a:hover { color: #e0e0e0; }

.btn-small {
  display: inline-block;
  padding: 4px 12px;
  font-size: 0.8rem;
  background: #e94560;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
.btn-small:hover { background: #c73e54; }
.btn-danger { background: #c0392b; }
.btn-danger:hover { background: #a93226; }
.btn-outline {
  background: transparent;
  border: 1px solid #0f3460;
  color: #aaa;
}
.btn-outline:hover { background: #0f3460; color: #e0e0e0; }

/* Auth pages */
.auth-container {
  max-width: 400px;
  margin: 60px auto;
  padding: 24px;
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 8px;
}

.auth-container h2 {
  color: #e94560;
  margin-bottom: 16px;
  text-align: center;
}

.auth-container .form-group {
  margin-bottom: 12px;
}

.auth-container .btn {
  width: 100%;
  margin-top: 8px;
}

.auth-link {
  display: block;
  text-align: center;
  margin-top: 12px;
  color: #aaa;
  font-size: 0.85rem;
}

.auth-link a { color: #e94560; }

/* Status page */
.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.status-card {
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 8px;
  padding: 16px;
}

.status-card h3 {
  color: #e94560;
  font-size: 1rem;
  margin-bottom: 12px;
}

.status-card .feed-table {
  margin-bottom: 0;
}

.status-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid #0f3460;
  font-size: 0.9rem;
}

.status-row:last-child {
  border-bottom: none;
}

.status-label {
  color: #aaa;
}

.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #666;
}

.status-dot.ok { background: #2ecc71; }
.status-dot.stale { background: #f1c40f; }
.status-dot.down { background: #e74c3c; }

/* ══════════════════════════════════════════════════════════════════════════════
   MOBILE — max-width: 768px
   ══════════════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {

  /* ── Navigation: hamburger menu ─────────────────────────────────────────── */
  .nav-hamburger {
    display: flex;
  }

  .nav-links {
    display: none !important;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #16213e;
    border-bottom: 1px solid #0f3460;
    flex-direction: column;
    padding: 8px 0;
    z-index: 2000;
    gap: 0;
  }

  .nav-links.open {
    display: flex !important;
  }

  #nav {
    position: relative;
    z-index: 2001;
  }

  .nav-links a {
    padding: 12px 20px;
    font-size: 1rem;
    min-height: 44px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #0f3460;
  }

  .nav-links a:last-child {
    border-bottom: none;
  }

  .nav-links a:active {
    background: #1a2d50;
  }

  /* ── Map layout: full screen, feed panel as bottom drawer ───────────────── */
  #content {
    flex-direction: column;
    position: relative;
  }

  #feed-panel {
    display: none !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    min-width: 0;
    max-height: 50vh;
    z-index: 1001;
    border-right: none;
    border-top: 2px solid #0f3460;
    background: #1a1a2e;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  #feed-panel.drawer-open {
    display: block !important;
    bottom: 72px;
  }

  #map-wrap {
    width: 100%;
    height: 100%;
  }

  /* Move Leaflet zoom controls to bottom-left so they don't overlap status */
  .leaflet-top.leaflet-left {
    top: auto !important;
    bottom: 70px;
  }

  /* Bottom button bar: feed (left) + legend (right) */
  #map-bottom-bar {
    display: flex !important;
    position: fixed;
    bottom: 24px;
    left: 60px;
    right: 12px;
    z-index: 1000;
    justify-content: space-between;
    pointer-events: none;
  }

  #drawer-toggle {
    display: flex;
    background: #16213e;
    border: 1px solid #0f3460;
    color: #e0e0e0;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    align-items: center;
    gap: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
    min-height: 44px;
    pointer-events: auto;
  }

  #drawer-toggle:active {
    background: #1a2d50;
  }

  #drawer-toggle .drawer-arrow {
    transition: transform 0.2s;
  }

  #drawer-toggle.open .drawer-arrow {
    transform: rotate(180deg);
  }

  /* Feed entries: bigger touch targets */
  .feed-entry {
    padding: 14px 16px;
  }

  .feed-entry .feed-event {
    font-size: 0.9rem;
  }

  .feed-entry .feed-location {
    font-size: 0.8rem;
  }

  .feed-entry .feed-time {
    font-size: 0.75rem;
  }

  /* Map status bar: compact pill, top-left below nav */
  #map-status {
    top: 8px;
    left: 8px;
    right: auto;
    gap: 8px;
    background: rgba(22, 33, 62, 0.85);
    padding: 4px 10px;
    border-radius: 16px;
    font-size: 0.75rem;
  }

  #count {
    font-size: 0.75rem;
    padding: 0;
    background: none;
    border-radius: 0;
  }

  #last-update {
    display: none;
  }

  /* Legend: hide Leaflet-positioned control on mobile, use bottom bar instead */
  .leaflet-bottom.leaflet-right .legend {
    display: none;
  }

  #mobile-legend-btn {
    display: flex;
    background: #16213e;
    border: 1px solid #0f3460;
    color: #e0e0e0;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
    min-height: 44px;
    pointer-events: auto;
  }

  #mobile-legend-btn:active {
    background: #1a2d50;
  }

  #mobile-legend-popup {
    display: none;
    position: fixed;
    bottom: 80px;
    right: 12px;
    z-index: 1002;
    background: #16213e;
    border: 1px solid #0f3460;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 0.75rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  }

  #mobile-legend-popup.open {
    display: block;
  }

  #mobile-legend-popup .legend-row {
    gap: 4px;
    margin: 2px 0;
  }

  /* Popup: constrain on mobile */
  .leaflet-popup-content-wrapper {
    max-width: 280px;
  }

  .popup-row {
    font-size: 0.85rem;
  }

  /* ── CAP detail modal: full screen on mobile ───────────────────────────── */
  #cap-detail-modal .cap-detail-content {
    width: 96%;
    max-height: 90vh;
    top: 50%;
  }

  /* ── Forms: bigger touch targets ───────────────────────────────────────── */
  .form-container {
    margin: 16px auto;
    padding-bottom: 60px;
  }

  .form-input, .form-select, input[type="text"], input[type="email"],
  input[type="password"], input[type="number"], select {
    padding: 12px;
    font-size: 1rem;
    min-height: 44px;
  }

  .btn {
    padding: 12px 24px;
    font-size: 1rem;
    min-height: 44px;
  }

  /* Tables → card layout on mobile */
  .feed-table {
    display: none;
  }

  .feed-card-row {
    min-height: 44px;
  }

  .feed-card-row input[type="text"],
  .feed-card-row select {
    min-height: 40px;
  }

  /* Status page: stack grid */
  .status-grid {
    grid-template-columns: 1fr;
  }

  /* Auth pages: reduce top margin */
  .auth-container {
    margin: 24px auto;
  }
}

/* ══════════════════════════════════════════════════════════════════════════════
   SMALL PHONES — max-width: 400px
   ══════════════════════════════════════════════════════════════════════════════ */

@media (max-width: 400px) {
  .legend {
    font-size: 0.65rem;
    padding: 4px 6px;
    max-width: 140px;
  }

  #map-status {
    gap: 4px;
    padding: 3px 8px;
  }

  #count {
    font-size: 0.7rem;
  }

  #drawer-toggle,
  #mobile-legend-btn {
    font-size: 0.8rem;
    padding: 8px 16px;
  }
}
