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

html, body {
  height: 100%;
  font-family: "Segoe UI", "Sukhumvit Set", "Noto Sans Thai", Tahoma, sans-serif;
}

body { display: flex; flex-direction: column; }

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  padding: 10px 18px;
  background: #0b3d2e;
  color: #fff;
  z-index: 1100;
}

.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand-icon { font-size: 28px; }
.brand h1 { font-size: 20px; line-height: 1.1; }
.brand p { font-size: 12px; opacity: 0.75; }

.search-box { position: relative; order: 10; flex: 1 1 100%; }
.search-box input {
  width: 100%;
  padding: 9px 14px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
}
#search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 320px;
  overflow-y: auto;
  background: #fff;
  color: #222;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  list-style: none;
  z-index: 1200;
}
#search-results li {
  padding: 9px 14px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid #eee;
}
#search-results li:hover { background: #eaf6ef; }

.stats { font-size: 13px; opacity: 0.85; white-space: nowrap; }

.preset-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
}
.preset-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  opacity: 0.6;
}
.preset-bar button {
  padding: 7px 14px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 20px;
  background: transparent;
  color: #fff;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.preset-bar button:hover { background: rgba(255, 255, 255, 0.15); }
.preset-bar button.active {
  background: #ffb300;
  border-color: #ffb300;
  color: #143024;
  font-weight: 700;
}

/* narrow screens: give the preset bar its own row so it doesn't crowd the
   logo and camera count */
@media (max-width: 640px) {
  header { gap: 10px 12px; padding: 10px 14px; }
  .brand { flex: 1; }
  .brand h1 { font-size: 18px; }
  .preset-bar { order: 9; flex: 1 1 100%; }
  .preset-label { flex-basis: 100%; margin-bottom: 2px; }
}

main { flex: 1; position: relative; }
#map { position: absolute; inset: 0; }

/* preset grid view */
#grid-view {
  position: absolute;
  inset: 0;
  background: #10231b;
  z-index: 1000;
  overflow-y: auto;
  padding: 16px 20px 28px;
}
.grid-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.grid-header h2 { color: #fff; font-size: 18px; font-weight: 600; }
#grid-close {
  padding: 7px 16px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  background: transparent;
  color: #fff;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
#grid-close:hover { background: rgba(255, 255, 255, 0.15); }
#grid-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}
.grid-tile {
  background: #0b3d2e;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.grid-tile .cam-view { border-radius: 0; }
.grid-tile figcaption {
  color: #e8f5ee;
  font-size: 13px;
  padding: 9px 12px;
}

/* camera popup — styled after bmatraffic's popup */
.leaflet-popup-content { margin: 10px 12px; }
.cam-popup { width: 420px; max-width: 82vw; }
.cam-popup .cam-title {
  color: #1a7a3c;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
  padding-right: 14px;
}
.cam-popup .cam-title small { color: #777; font-weight: 400; }
.cam-view {
  position: relative;
  width: 100%;
  aspect-ratio: 400 / 266;
  background: #111;
  border-radius: 6px;
  overflow: hidden;
}
.cam-view img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.cam-view .cam-status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ccc;
  font-size: 13px;
  background: rgba(0, 0, 0, 0.55);
  transition: opacity 0.3s;
}
.cam-view .cam-status.hidden { opacity: 0; pointer-events: none; }
.cam-live {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(200, 30, 30, 0.9);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  letter-spacing: 0.5px;
  display: none;
}
.cam-live.on { display: block; }
