:root{
  --bg:#0b1220;
  --panel:#0f1a30;
  --card:#121f3a;
  --muted:#93a4c7;
  --text:#e9efff;
  --border: rgba(255,255,255,.08);
  --accent:#4b8bff;
  --accent2:#20c997;
  --danger:#ff5d5d;
}

*{box-sizing:border-box}
body{
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  padding:12px 16px;
  border-bottom:1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,0));
}

.brand{display:flex; gap:12px; align-items:center}
.logo{
  width:36px;height:36px;border-radius:10px;
  display:flex;align-items:center;justify-content:center;
  overflow:hidden;
  background: transparent;
}
.logo img{
  width:100%;
  height:100%;
  object-fit:contain;
  display:block;
}
.brand-text .title{font-weight:800}
.brand-text .subtitle{color:var(--muted);font-size:12px}

.controls{
  display:flex;
  gap:10px;
  align-items:end;
  flex-wrap:wrap;
}
.control{
  display:flex;
  flex-direction:column;
  gap:6px;
}
label{font-size:12px;color:var(--muted)}
input,select{
  height:34px;
  border-radius:10px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.04);
  color: var(--text);
  padding:0 10px;
  outline:none;
}
input::placeholder{color: rgba(233,239,255,.45)}
.btn{
  height:34px;
  border-radius:10px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.06);
  color: var(--text);
  padding:0 12px;
  cursor:pointer;
}
.btn.primary{
  background: var(--accent);
  border-color: rgba(75,139,255,.5);
  font-weight:700;
}

.layout{
  display:grid;
  grid-template-columns: 1fr 2fr 1fr;
  gap:12px;
  padding:12px;
  height: calc(100vh - 70px);
}

.panel{
  overflow:auto;
  background: rgba(255,255,255,.03);
  border:1px solid var(--border);
  border-radius:16px;
  padding:12px;
}

.panel-header{
  display:flex;
  align-items:baseline;
  justify-content:space-between;
  gap:12px;
  margin-bottom:10px;
}
.panel-header h2{margin:0;font-size:18px}
.hint{color:var(--muted);font-size:12px}

.kpi-grid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:10px;
  margin-bottom:10px;
}
.kpi{
  background: var(--card);
  border:1px solid var(--border);
  border-radius:14px;
  padding:12px;
}
.kpi-label{color:var(--muted);font-size:12px}
.kpi-value{font-size:26px;font-weight:900;margin-top:6px}

.chart-grid{
  display:grid;
  grid-template-columns: 1fr;
  gap:10px;
  margin-bottom:10px;
}
.card{
  background: var(--card);
  border:1px solid var(--border);
  border-radius:14px;
  padding:12px;
  margin-bottom:12px;
}
.card-title{
  font-weight:800;
  margin-bottom:8px;
  font-size:13px;
  color: rgba(233,239,255,.9);
}

.map-wrap{
  border:1px solid var(--border);
  border-radius:16px;
  overflow:hidden;
  position:relative;
  background: rgba(255,255,255,.03);
}
#map{
  width:100%;
  height: calc(100% - 44px);
}
.map-footer{
  height:44px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:0 12px;
  border-top:1px solid var(--border);
  background: rgba(0,0,0,.25);
  color: var(--muted);
  font-size:12px;
}

.table-wrap{overflow:auto; max-height: 320px; border-radius:12px}
.table{
  width:100%;
  border-collapse:collapse;
  font-size:12px;
}
.table th, .table td{
  border-bottom: 1px solid rgba(255,255,255,.06);
  padding:10px 8px;
  text-align:left;
  white-space:nowrap;
}
.table th{color:var(--muted); font-weight:700}
.badge{
  padding:3px 8px;
  border-radius:999px;
  font-weight:700;
  display:inline-block;
  font-size:11px;
}
.badge.ok{background: rgba(32,201,151,.15); color: var(--accent2); border:1px solid rgba(32,201,151,.35)}
.badge.warn{background: rgba(255,93,93,.12); color: var(--danger); border:1px solid rgba(255,93,93,.35)}
.badge.neutral{background: rgba(255,255,255,.06); color: rgba(233,239,255,.85); border:1px solid rgba(255,255,255,.12)}

@media (max-width: 1400px){
  .layout{grid-template-columns: 1fr; height:auto}
  #map{height: 420px}
  .dashboard-panel, .side-panel{display:block}
}


/* ----------------------------
   Right-side Portfolio Summary
   ---------------------------- */
.side-panel .panel-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:10px;}
.stats-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px;margin-bottom:12px;}
.stat-card{border:1px solid rgba(255,255,255,.08);background:linear-gradient(180deg,rgba(255,255,255,.06),rgba(255,255,255,.03));border-radius:14px;padding:12px;box-shadow:0 6px 18px rgba(0,0,0,.25);}
.stat-top{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:6px;}
.stat-icon{width:36px;height:26px;border-radius:8px;display:flex;align-items:center;justify-content:center;color:#cfe3ff;background:rgba(120,170,255,.14);}
.stat-icon svg{width:20px;height:20px;}
.stat-value{font-size:28px;font-weight:700;letter-spacing:.3px;}
.stat-label{font-size:12px;opacity:.9;margin-top:2px;}
.stat-sub{margin-top:8px;font-size:12px;opacity:.9;display:flex;flex-direction:column;gap:4px;}
.muted{opacity:.75;}
.stat-card.stat-total{grid-column:span 1;}
/* tint bars like the reference mock */
.stat-good .stat-icon{background:rgba(80,200,120,.16);color:#b9f6c8;}
.stat-attn .stat-icon{background:rgba(255,180,60,.18);color:#ffe0a6;}
.stat-critical .stat-icon{background:rgba(255,80,120,.18);color:#ffb3c9;}
.stat-good .stat-sub, .stat-attn .stat-sub, .stat-critical .stat-sub{font-weight:600;}
.chart-card{border:1px solid rgba(255,255,255,.08);border-radius:14px;padding:12px;background:linear-gradient(180deg,rgba(255,255,255,.04),rgba(255,255,255,.02));}
.chart-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:8px;}
.chart-card h3{font-size:14px;margin:0;}
.chart-container{position:relative;width:100%;height:180px;margin-bottom:8px;}
.chart-hint{margin-top:8px;font-size:12px;opacity:.75;line-height:1.3;}

/* Layers Section */
.layers-list{display:flex;flex-direction:column;gap:8px;}
.layer-item{display:flex;align-items:center;gap:8px;}
.layer-item input[type="checkbox"]{width:16px;height:16px;cursor:pointer;}
.layer-item label{font-size:13px;cursor:pointer;color:rgba(233,239,255,.9);}
.layer-item label:hover{opacity:.8;}

/* MapLibre Controls */
.maplibre-ctrl-basemap{
  display:flex;
  gap:8px;
  background:transparent;
  border:none;
  padding:12px;
}
.basemap-btn{
  padding:8px 16px;
  border-radius:6px;
  border:none;
  background:#1a2332;
  color:rgba(255,255,255,.85);
  font-size:13px;
  font-weight:600;
  cursor:pointer;
  transition:all 0.2s ease;
  box-shadow:0 2px 8px rgba(0,0,0,.3);
}
.basemap-btn:hover{
  background:#242f42;
  transform:translateY(-1px);
  box-shadow:0 4px 12px rgba(0,0,0,.4);
}
.basemap-btn.active{
  background:var(--accent);
  color:white;
  box-shadow:0 2px 8px rgba(75,139,255,.5);
}


/* --- Map popup: scores + details (color-coded like dashboard cards) --- */
.popup-wrap{min-width:280px;max-width:360px;color:#e9eefc;}
.popup-header{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:8px;}
.popup-title{font-weight:800;font-size:14px;line-height:1.2;}
.popup-badge{padding:3px 8px;border-radius:999px;font-size:12px;border:1px solid rgba(255,255,255,.18);background:rgba(255,255,255,.06);white-space:nowrap;}
.popup-badge.stat-good{background:rgba(80,200,120,.16);border-color:rgba(80,200,120,.28);color:#b9f3c9;}
.popup-badge.stat-attn{background:rgba(255,180,60,.18);border-color:rgba(255,180,60,.28);color:#ffe0a6;}
.popup-badge.stat-critical{background:rgba(255,90,150,.16);border-color:rgba(255,90,150,.28);color:#ffc2dd;}

.popup-meta{display:grid;gap:4px;margin-bottom:10px;font-size:12px;opacity:.95;}
.popup-section-title{margin:10px 0 6px 0;font-size:12px;font-weight:800;letter-spacing:.02em;opacity:.9;text-transform:uppercase;}

.popup-bars{display:grid;gap:6px;}
.popup-bar-row{display:grid;grid-template-columns:34px 1fr 28px;gap:8px;align-items:center;}
.popup-bar-label{font-size:12px;opacity:.9;}
.popup-bar-val{font-size:12px;opacity:.9;text-align:right;}
.popup-bar{height:8px;border-radius:999px;background:rgba(255,255,255,.08);overflow:hidden;}
.popup-bar span{display:block;height:100%;width:0%;}
.popup-bar.stat-good span{background:rgba(80,200,120,.85);}
.popup-bar.stat-attn span{background:rgba(255,180,60,.85);}
.popup-bar.stat-critical span{background:rgba(255,90,150,.85);}
.popup-bar.stat-total span{background:rgba(147,164,199,.85);}

.popup-table{width:100%;border-collapse:collapse;font-size:12px;}
.popup-table th{width:38%;text-align:left;padding:6px 6px 6px 0;opacity:.8;vertical-align:top;}
.popup-table td{padding:6px 0;opacity:.95;word-break:break-word;}
.popup-table tr+tr th,.popup-table tr+tr td{border-top:1px solid rgba(255,255,255,.08);}

/* Cleaner topbar controls */
.controls-clean {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.controls-clean .control label {
  font-size: 12px;
  opacity: 0.85;
}

.controls-clean .control input,
.controls-clean .control select {
  min-width: 180px;
}

.controls-clean .control-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-left: 6px;
}

.controls-clean .advanced {
  margin-left: auto; /* pushes Advanced to the right on wide screens */
}

.controls-clean .advanced summary {
  cursor: pointer;
  user-select: none;
  font-size: 12px;
  opacity: 0.9;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.10);
}

.controls-clean .advanced[open] summary {
  background: rgba(255,255,255,0.10);
}

.controls-clean .advanced-body {
  margin-top: 10px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(0,0,0,0.20);
  border: 1px solid rgba(255,255,255,0.10);
}


/* ---- MapLibre popup: dark theme ---- */
.maplibregl-popup-content{
  background: rgba(34, 40, 52, 0.96);
  color:#e9eefc;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.45);
}
.maplibregl-popup-close-button{
  color:#e9eefc;
  font-size: 18px;
  padding: 6px 10px;
  border-radius: 10px;
}
.maplibregl-popup-close-button:hover{
  background: rgba(255,255,255,0.08);
}
.maplibregl-popup-tip{
  border-top-color: rgba(34, 40, 52, 0.96) !important;
  border-bottom-color: rgba(34, 40, 52, 0.96) !important;
}

/* ---- Popup tweaks ---- */
.popup-title-sep{opacity:.7; margin:0 4px;}
.popup-title-uid{font-weight:700; opacity:.95;}

.popup-scores{
  border:1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.04);
  border-radius: 12px;
  padding: 10px;
  margin-top: 10px;
}
.popup-scores .popup-section-title{
  margin: 0 0 8px 0;
}
.popup-scores-hint{
  margin-top: 8px;
  font-size: 11px;
  opacity: .75;
}

/* Score bars: show value on click (hover uses title="") */
.popup-bar-row{
  position: relative;
  cursor: pointer;
  padding: 3px 2px;
  border-radius: 10px;
}
.popup-bar-row:hover{
  background: rgba(255,255,255,0.04);
}
.popup-bar-row.show-tip::after{
  content: attr(data-tip);
  position: absolute;
  left: 6px;
  top: -28px;
  background: rgba(0,0,0,0.75);
  color: #fff;
  padding: 4px 8px;
  border-radius: 10px;
  font-size: 11px;
  white-space: nowrap;
  pointer-events: none;
  border: 1px solid rgba(255,255,255,0.16);
}

/* ---- Popup sizing + scrolling (shorter, scrollable, visible scrollbar) ---- */
.maplibregl-popup-content{
  /* wider so content fits horizontally */
  width: clamp(360px, 40vw, 520px);
  max-width: 92vw;

  /* shorter vertically + scroll */
  max-height: 360px;
  overflow-y: auto;
  overflow-x: hidden;

  /* slightly tighter padding so it feels less “tall” */
  padding: 12px 12px;
}

/* Make tables wrap nicely instead of forcing height */
.popup-table th { white-space: nowrap; }
.popup-table td { word-break: break-word; }

/* Visible scrollbar */
.maplibregl-popup-content{
  scrollbar-width: thin;                 /* Firefox */
  scrollbar-color: rgba(255,255,255,.35) rgba(255,255,255,.08);
}
.maplibregl-popup-content::-webkit-scrollbar{
  width: 10px;
}
.maplibregl-popup-content::-webkit-scrollbar-track{
  background: rgba(255,255,255,.06);
  border-radius: 999px;
}
.maplibregl-popup-content::-webkit-scrollbar-thumb{
  background: rgba(255,255,255,.28);
  border-radius: 999px;
  border: 2px solid rgba(0,0,0,0); /* keeps it chunky */
  background-clip: padding-box;
}
.maplibregl-popup-content::-webkit-scrollbar-thumb:hover{
  background: rgba(255,255,255,.40);
}

/* ---- Score bar colors by bucket ---- */
.popup-bar{
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.10);
  overflow: hidden;
}
.popup-bar > span{
  display: block;
  height: 100%;
  border-radius: 999px;
}

/* good / attention / critical */
.popup-bar.stat-good > span     { background: rgba(32,201,151,.90); }
.popup-bar.stat-attn > span     { background: rgba(244,163,64,.90); }
.popup-bar.stat-critical > span { background: rgba(255,90,95,.92); }
.popup-bar.stat-total > span    { background: rgba(147,164,199,.85); }


.chart-actions{
  display:flex;
  gap:8px;
  margin-top:10px;
}
.btn.btn-sm{
  padding:6px 10px;
  font-size:12px;
  border-radius:10px;
}


/* --- Submissions actions/buttons --- */
.pillBtn {
  border: 1px solid rgba(0,0,0,0.15);
  background: rgba(255,255,255,0.9);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
}
.pillBtn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.actionsCell {
  white-space: nowrap;
}
.muted {
  opacity: 0.7;
}
#submissionsTable tbody tr:hover {
  background: rgba(0,0,0,0.03);
}


/* --- Auth bar --- */
.authBar{
  margin-left:auto;
  display:flex;
  align-items:center;
  gap:10px;
}
.linkBtn{
  color:#cfe3ff;
  text-decoration:none;
  border:1px solid rgba(255,255,255,.15);
  padding:8px 10px;
  border-radius:10px;
  background:rgba(255,255,255,.04);
}
.linkBtn:hover{
  background:rgba(255,255,255,.08);
}

/* --- Collapsible device registry --- */
#deviceRegistryToggle > summary{
  list-style:none;
}
#deviceRegistryToggle > summary::-webkit-details-marker{
  display:none;
}
#deviceRegistryToggle > summary::after{
  content:"▾";
  float:right;
  opacity:.7;
}
#deviceRegistryToggle[open] > summary::after{
  content:"▴";
}

.pillBtn.danger{ border-color: rgba(255,0,0,0.35); background: rgba(255,220,220,0.95); }
.pillBtn.danger:hover{ filter: brightness(0.98); }

/* === FIX: select dropdown options invisible (dark theme vs native white list) === */
#deviceSelect,
.device-select {
  background-color: #ffffff;
  color: #111827;
}

#deviceSelect option,
.device-select option {
  color: #111827;
}



/* Device Registry toggle header */
.card-title-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}

.icon-btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:34px;
  height:34px;
  border-radius:10px;
  border:1px solid rgba(255,255,255,.12);
  background:rgba(255,255,255,.06);
  color:#e9efff;
  cursor:pointer;
}

.icon-btn:hover{
  background:rgba(255,255,255,.10);
}

.device-registry-body.collapsed{
  display:none;
}

.icon-btn.active{
  background:rgba(110,168,255,.18);
  border-color:rgba(110,168,255,.25);
}


/* Device Registry toggle icon button (Font Awesome) */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.9);
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255,255,255,0.10); }
.icon-btn i { font-size: 14px; line-height: 1; }


/* Popup thumbnail grid */
.popup-thumb-grid{
  display:grid;
  grid-template-columns:repeat(3,1fr);
  gap:6px;
}
.popup-thumb{
  padding:0;
  border:1px solid rgba(255,255,255,.12);
  background:rgba(255,255,255,.06);
  border-radius:10px;
  overflow:hidden;
  cursor:pointer;
}
.popup-thumb img{
  width:100%;
  height:70px;           /* thumbnail height */
  object-fit:cover;      /* crop to fit */
  display:block;
}

.photo-modal-img{
  width:100%;
  max-height:76vh;
  object-fit:contain;  /* show full image inside modal */
  background: rgba(0,0,0,.35);
  border-radius:10px;
}

/* Support layers (Layers card) */
.support-layers { margin-top: 10px; }
.support-layers > summary {
  cursor: pointer;
  font-weight: 600;
  padding: 6px 0;
  user-select: none;
}
.support-layers[open] > summary { margin-bottom: 6px; }
.support-layers-list .layer-item { margin-left: 6px; }


/* Export Report button */
.exportBtn{
  padding:10px 14px;
  font-weight:700;
  border-radius:10px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
}

/* Modal overlay: true center */
.photo-modal{
  position: fixed;
  inset: 0;
  z-index: 999999;
  background: rgba(0,0,0,0.72);

  /* center the card */
  display: none;                /* JS sets to flex */
  align-items: center;
  justify-content: center;

  /* avoid top-left due to padding/scroll */
  padding: 18px;
  box-sizing: border-box;
}

/* Ensure the card itself doesn't get pinned */
.photo-modal-card{
  position: relative;
  margin: 0;                    /* remove any inherited margins */
  width: min(1100px, 96vw);
  max-height: 92vh;

  overflow: hidden;
  border-radius: 16px;
  background: #0b1220;
  box-shadow: 0 16px 50px rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.12);

  display: flex;
  flex-direction: column;
}

/* If ANY parent styles are forcing absolute positioning somewhere */
.photo-modal,
.photo-modal *{
  box-sizing: border-box;
}

/* prevent background scrolling while modal open */
.modal-open{
  overflow: hidden;
}