/* ===========================================================
   WatR — Alipurduar River Photo WebGIS
   Premium, colorful, glass-panelled dashboard theme
   =========================================================== */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@500;600;700;800&family=Inter:wght@400;500;600&display=swap');

:root {
  --bg-0: #070b18;
  --bg-1: #0c1330;
  --bg-2: #121a3d;
  --panel: rgba(22, 30, 61, 0.72);
  --panel-solid: #141b3a;
  --panel-2: rgba(30, 40, 78, 0.55);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #eef1fb;
  --text-dim: #9aa4c7;

  /* River-inspired vivid accent palette */
  --c1: #22d3ee; /* cyan */
  --c2: #38bdf8; /* sky */
  --c3: #818cf8; /* indigo */
  --c4: #f472b6; /* pink */
  --c5: #fb923c; /* orange */
  --c6: #34d399; /* emerald */

  --accent: var(--c1);
  --accent-2: var(--c3);
  --danger: #fb7185;
  --ok: #34d399;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 20px 50px -12px rgba(3, 8, 24, 0.65);
  --shadow-sm: 0 8px 20px -6px rgba(3, 8, 24, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(900px 500px at 8% -10%, rgba(129, 140, 248, 0.28), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(34, 211, 238, 0.20), transparent 55%),
    radial-gradient(700px 500px at 50% 110%, rgba(244, 114, 182, 0.14), transparent 55%),
    var(--bg-0);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

h1, h2, h3, .display {
  font-family: 'Outfit', 'Inter', sans-serif;
}

#app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: 100%;
  height: 100vh;
  min-width: 0;
}

/* Every direct grid row/column below must be allowed to shrink below its
   content's natural width, or a single wide row (the 46-photo filmstrip)
   silently stretches the ENTIRE app off-screen — this is what caused the
   header's stats/buttons to vanish off the right edge. */
header.topbar, main.layout, footer.filmstrip, aside.sidebar, .map-wrap {
  min-width: 0;
  min-height: 0;
}

/* ---------- Header ---------- */
header.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  row-gap: 8px;
  gap: 18px;
  padding: 14px 22px;
  background: linear-gradient(115deg, #0a0f26 0%, #121a3f 45%, #171c40 100%);
  border-bottom: 1px solid var(--border);
  z-index: 30;
  overflow: hidden;
}
header.topbar::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--c1), var(--c3), var(--c4), var(--c5), var(--c1));
  background-size: 300% 100%;
  animation: flow 8s linear infinite;
}
@keyframes flow {
  0% { background-position: 0% 0; }
  100% { background-position: 300% 0; }
}

header.topbar h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 700;
  letter-spacing: .1px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(95deg, #f4f7ff 10%, var(--c1) 55%, var(--c3) 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
header.topbar h1 .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--c1);
  box-shadow: 0 0 0 4px rgba(34,211,238,.18), 0 0 14px var(--c1);
  animation: pulse 2.4s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(34,211,238,.18), 0 0 14px var(--c1); }
  50% { box-shadow: 0 0 0 7px rgba(34,211,238,.08), 0 0 20px var(--c1); }
}
header.topbar .subtitle {
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 3px;
  font-weight: 500;
}
.stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.stat-pill {
  background: var(--panel-2);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  font-weight: 500;
  transition: transform .15s ease, border-color .15s ease;
}
.stat-pill:hover { transform: translateY(-1px); border-color: var(--border-strong); }
.stat-pill b { color: var(--text); font-weight: 700; }
.stat-pill.c1 { border-color: rgba(34,211,238,.35); } .stat-pill.c1 b { color: var(--c1); }
.stat-pill.c2 { border-color: rgba(52,211,153,.35); } .stat-pill.c2 b { color: var(--c6); }
.stat-pill.c3 { border-color: rgba(129,140,248,.35); } .stat-pill.c3 b { color: var(--c3); }
.stat-pill.c4 { border-color: rgba(251,146,60,.35); } .stat-pill.c4 b { color: var(--c5); }

.header-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- Layout ---------- */
main.layout {
  display: grid;
  grid-template-columns: 310px 1fr;
  min-height: 0;
}

/* ---------- Sidebar ---------- */
aside.sidebar {
  background: linear-gradient(180deg, #0c1230, #0a0e24);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sidebar h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--text-dim);
  margin: 0 0 10px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
}
.sidebar-section {
  background: var(--panel);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

input[type="text"], select, textarea {
  width: 100%;
  background: rgba(5, 9, 22, 0.65);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
  font-family: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input[type="text"]:focus, select:focus, textarea:focus {
  border-color: var(--c1);
  box-shadow: 0 0 0 3px rgba(34,211,238,.15);
}
label { font-size: 11px; color: var(--text-dim); display: block; margin: 10px 0 5px; font-weight: 600; }
label:first-child { margin-top: 0; }

.btn {
  background: linear-gradient(120deg, var(--c1), var(--c2) 55%, var(--c3));
  color: #04121f;
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: filter .15s ease, transform .15s ease, box-shadow .15s ease;
  box-shadow: 0 6px 16px -4px rgba(34,211,238,.35);
}
.btn:hover { filter: brightness(1.06); transform: translateY(-1px); box-shadow: 0 10px 22px -6px rgba(34,211,238,.45); }
.btn:active { transform: translateY(0); }
.btn.secondary {
  background: rgba(255,255,255,.06);
  border: 1px solid var(--border-strong);
  color: var(--text);
  box-shadow: none;
}
.btn.secondary:hover { background: rgba(255,255,255,.1); box-shadow: none; }
.btn.danger { background: linear-gradient(120deg, var(--danger), #f43f5e); color: #2a0a0f; box-shadow: 0 6px 16px -4px rgba(251,113,133,.4); }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.river-legend { display: flex; flex-direction: column; gap: 3px; margin-top: 6px; }
.river-legend-item {
  display: flex; align-items: center; gap: 9px; font-size: 12.5px; color: var(--text-dim);
  cursor: pointer; padding: 6px 8px; border-radius: 8px; font-weight: 500;
  transition: background .15s ease, color .15s ease;
}
.river-legend-item:hover { background: rgba(255,255,255,.05); color: var(--text); }
.river-legend-item.active { color: var(--text); background: rgba(34,211,238,.12); }
.swatch {
  width: 12px; height: 12px; border-radius: 4px; flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(255,255,255,.15) inset, 0 0 8px -2px currentColor;
}
.legend-count {
  margin-left: auto; color: var(--text-dim); font-variant-numeric: tabular-nums;
  background: rgba(255,255,255,.06); padding: 1px 7px; border-radius: 999px; font-size: 11px;
}

/* Unplaced tray */
.tray-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-top: 10px;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 2px;
}
.tray-item {
  position: relative;
  border-radius: 9px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  aspect-ratio: 1 / 1;
  background: #0c1322;
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.tray-item:hover { transform: translateY(-2px) scale(1.02); box-shadow: var(--shadow-sm); }
.tray-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tray-item.selected { border-color: var(--c1); box-shadow: 0 0 0 3px rgba(34,211,238,.3); }
.tray-item .idx {
  position: absolute; top: 3px; left: 3px;
  background: rgba(5,9,22,.72); backdrop-filter: blur(3px); color: #fff; font-size: 9px;
  font-weight: 700; padding: 2px 5px; border-radius: 5px;
}
.tray-empty { font-size: 12px; color: var(--text-dim); padding: 14px 6px; line-height: 1.5; }

.placing-banner {
  display: none;
  background: linear-gradient(120deg, rgba(34,211,238,.16), rgba(129,140,248,.16));
  border: 1px solid rgba(34,211,238,.5);
  color: var(--c1);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 12px;
  font-weight: 600;
  margin-top: 10px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.placing-banner.show { display: flex; animation: slideIn .2s ease; }
@keyframes slideIn { from { opacity: 0; transform: translateY(-4px);} to { opacity:1; transform:none; } }

/* Skeleton loading */
.skeleton {
  background: linear-gradient(100deg, rgba(255,255,255,.04) 30%, rgba(255,255,255,.1) 50%, rgba(255,255,255,.04) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
  border-radius: 9px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---------- Map ---------- */
.map-wrap { position: relative; min-height: 0; }
#map { width: 100%; height: 100%; background: #0b1220; }

.leaflet-popup-content-wrapper {
  background: var(--panel-solid);
  color: var(--text);
  border-radius: 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-strong);
}
.leaflet-popup-tip { background: var(--panel-solid); }
.leaflet-popup-close-button { color: var(--text-dim) !important; }
.popup-card { width: 260px; }
.popup-card img {
  width: 100%; height: 140px; object-fit: cover; border-radius: 10px; margin-bottom: 9px;
  cursor: zoom-in;
  transition: filter .15s ease;
}
.popup-card img:hover { filter: brightness(1.08); }
.popup-card h3 { margin: 0 0 4px; font-size: 14px; font-weight: 700; }
.popup-meta { font-size: 11px; color: var(--text-dim); margin-bottom: 7px; font-weight: 500; }
.popup-notes { font-size: 12.5px; color: var(--text); margin-bottom: 10px; white-space: pre-wrap; line-height: 1.4; }
.popup-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.popup-actions .btn { flex: 1 1 auto; white-space: nowrap; }
.river-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 999px;
  background: rgba(255,255,255,.08); margin-bottom: 7px;
}

.leaflet-control-layers {
  background: var(--panel-solid) !important;
  color: var(--text) !important;
  border: 1px solid var(--border-strong) !important;
  border-radius: var(--radius-sm) !important;
  box-shadow: var(--shadow-sm) !important;
}
.leaflet-control-layers-toggle { filter: invert(1); }
.leaflet-bar a {
  background: var(--panel-solid) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}
.leaflet-bar a:hover { background: #1c2550 !important; }
.leaflet-control-scale-line {
  background: rgba(20,27,58,.75) !important;
  color: var(--text) !important;
  border-color: var(--border-strong) !important;
  backdrop-filter: blur(6px);
}

/* ---------- Filmstrip ---------- */
footer.filmstrip {
  background: linear-gradient(180deg, #0c1230, #090d20);
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.filmstrip .label {
  font-size: 11px; color: var(--text-dim); white-space: nowrap; padding-right: 4px;
  font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
}
.filmstrip-track {
  display: flex;
  flex: 1;
  min-width: 0;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.film-item {
  position: relative;
  width: 58px; height: 58px;
  flex-shrink: 0;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  opacity: .5;
  transition: transform .15s ease, opacity .15s ease, border-color .15s ease;
}
.film-item.placed { opacity: 1; }
.film-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.film-item .river-dot {
  position: absolute; bottom: 3px; right: 3px;
  width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid rgba(6,10,24,.8);
  box-shadow: 0 0 6px -1px currentColor;
}
.film-item:hover { border-color: var(--c1); transform: translateY(-2px); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(3,6,16,.72); backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center; z-index: 1000;
}
.modal-overlay.show { display: flex; animation: fadeIn .15s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--panel-solid);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  width: 390px;
  max-width: 92vw;
  padding: 20px;
  box-shadow: var(--shadow);
  animation: scaleIn .18s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes scaleIn { from { opacity: 0; transform: scale(.96) translateY(6px); } to { opacity: 1; transform: none; } }
.modal h3 { margin: 0 0 4px; font-size: 16px; font-weight: 700; }
.modal .modal-sub { font-size: 12px; color: var(--text-dim); margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-thumb { width: 100%; height: 150px; object-fit: cover; border-radius: 12px; margin-bottom: 10px; box-shadow: var(--shadow-sm); }

.lightbox {
  position: fixed; inset: 0; background: rgba(2,4,12,.9); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center; z-index: 1200;
  cursor: zoom-out;
}
.lightbox.show { display: flex; animation: fadeIn .15s ease; }
.lightbox img { max-width: 92vw; max-height: 90vh; border-radius: 10px; box-shadow: var(--shadow); }

.toast {
  position: fixed; bottom: 82px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel-solid); border: 1px solid var(--border-strong); color: var(--text);
  padding: 10px 18px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: all .25s cubic-bezier(.2,.9,.3,1.2);
  z-index: 1100;
  display: flex; align-items: center; gap: 8px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex-shrink: 0; }
.toast.error .dot { background: var(--danger); }

/* ---------- Premium photo frame ---------- */
.photo-frame {
  position: relative;
  padding: 10px 10px 34px;
  background: linear-gradient(160deg, #fbfbff, #eef0fb);
  border-radius: 14px;
  box-shadow: var(--shadow), 0 0 0 1px rgba(255,255,255,.06);
  transform: rotate(-0.6deg);
  transition: transform .25s ease, box-shadow .25s ease;
}
.photo-frame:hover { transform: rotate(0deg) translateY(-2px); }
.photo-frame .mat {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: #0b1220;
}
.photo-frame .mat img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photo-frame .mat::after {
  /* subtle inner vignette for a "printed photo" feel */
  content: '';
  position: absolute; inset: 0;
  box-shadow: inset 0 0 24px rgba(0,0,0,.18);
  pointer-events: none;
}
.photo-frame .frame-caption {
  position: absolute;
  left: 0; right: 0; bottom: 8px;
  text-align: center;
  font-family: 'Outfit', sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: #4b5170;
  letter-spacing: .02em;
}
.photo-frame .corner-tag {
  position: absolute;
  top: -8px; left: 14px;
  font-size: 10px;
  font-weight: 700;
  color: #04121f;
  padding: 3px 10px 3px 8px;
  border-radius: 0 0 6px 6px;
  box-shadow: var(--shadow-sm);
  letter-spacing: .03em;
}

/* ---------- Site card (premium detail view) ---------- */
.site-card-overlay {
  position: fixed; inset: 0; background: rgba(3,6,16,.78); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center; z-index: 1050; padding: 24px;
}
.site-card-overlay.show { display: flex; animation: fadeIn .18s ease; }
.site-card {
  width: 420px;
  max-width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  background: linear-gradient(165deg, #171f45, #0f1530);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 22px;
  box-shadow: var(--shadow);
  animation: scaleIn .2s cubic-bezier(.2,.9,.3,1.2);
}
.site-card .sc-close {
  float: right;
  background: rgba(255,255,255,.08);
  border: none; color: var(--text);
  width: 28px; height: 28px; border-radius: 50%;
  cursor: pointer; font-size: 14px; line-height: 28px; text-align: center;
}
.site-card .sc-close:hover { background: rgba(255,255,255,.16); }
.site-card .photo-frame { width: 100%; margin-bottom: 16px; }
.site-card .photo-frame .mat { aspect-ratio: 4/3; cursor: zoom-in; }
.site-card h3.sc-title {
  margin: 4px 0 2px; font-size: 19px; font-weight: 700; clear: both;
}
.site-card .sc-sub { font-size: 12px; color: var(--text-dim); margin-bottom: 14px; }
.sc-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.sc-info-cell {
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
}
.sc-info-cell .sc-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-dim); font-weight: 700; margin-bottom: 3px;
}
.sc-info-cell .sc-value { font-size: 13px; font-weight: 600; color: var(--text); }
.sc-info-cell.wide { grid-column: 1 / -1; }
.sc-notes {
  font-size: 13px; line-height: 1.5; color: var(--text);
  background: rgba(255,255,255,.03); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 16px; white-space: pre-wrap;
}
.sc-qr-row {
  display: flex; align-items: center; gap: 14px;
  background: linear-gradient(120deg, rgba(34,211,238,.09), rgba(129,140,248,.09));
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 16px;
}
.sc-qr-box {
  flex-shrink: 0; width: 84px; height: 84px; border-radius: 10px;
  background: #fff; padding: 5px; box-shadow: var(--shadow-sm);
  display: flex; align-items: center; justify-content: center;
}
.sc-qr-box img, .sc-qr-box canvas { width: 100%; height: 100%; display: block; }
.sc-qr-text { font-size: 12px; color: var(--text-dim); line-height: 1.5; }
.sc-qr-text b { color: var(--text); display: block; font-size: 13px; margin-bottom: 2px; }
.sc-unplaced-note {
  font-size: 12.5px; color: var(--text-dim); background: rgba(255,255,255,.04);
  border: 1px dashed var(--border-strong); border-radius: 12px; padding: 12px 14px; margin-bottom: 16px;
  text-align: center;
}
.site-card .sc-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.site-card .sc-actions .btn { flex: 1; min-width: 120px; text-align: center; text-decoration: none; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 820px) {
  main.layout { grid-template-columns: 1fr; }
  aside.sidebar { display: none; }
  .sc-info-grid { grid-template-columns: 1fr; }
}
