
:root {
  --bg: #0b1020;
  --panel: #111827;
  --panel2: #0f172a;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: rgba(255,255,255,.12);
  --accent: #60a5fa;
  --accent2: #34d399;
  --danger: #fca5a5;
  --state-green: #34d399;
  --state-yellow: #fbbf24;
  --state-red: #f87171;
  --state-gray: #94a3b8;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #08101f 0%, #111827 100%);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(8,16,31,.9);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand h1 {
  margin: 0 0 6px 0;
  font-size: 24px;
  line-height: 1.1;
}
.brand p {
  margin: 0;
  color: var(--muted);
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.legendItem {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 12px;
}
.legendItem::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 999px;
}
.legendGreen::before { background: var(--state-green); }
.legendYellow::before { background: var(--state-yellow); }
.legendRed::before { background: var(--state-red); }

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: end;
  justify-content: flex-end;
}
.modeSwitch {
  display: inline-flex;
  gap: 8px;
  padding: 6px;
  border-radius: 16px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
}
.modeBtn, .actionBtn {
  border: 0;
  color: var(--text);
  background: transparent;
  border-radius: 12px;
  padding: 10px 13px;
  cursor: pointer;
  font-weight: 600;
}
.modeBtn.active {
  background: rgba(96,165,250,.18);
  outline: 1px solid rgba(96,165,250,.35);
}
.actionBtn {
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
}
.actionBtn.active {
  background: rgba(52,211,153,.16);
  outline: 1px solid rgba(52,211,153,.35);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.search input {
  width: 280px;
  max-width: 60vw;
}
input[type="search"], input[type="file"] {
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.04);
  color: var(--text);
  padding: 11px 12px;
}
.toggle {
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.03);
}
.filepicker {
  min-width: 210px;
}
.filepicker input { width: 100%; }

.app {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(320px, .9fr);
  gap: 16px;
  padding: 16px;
  min-height: calc(100vh - 86px);
}
.workspace, .details {
  border: 1px solid var(--border);
  background: rgba(255,255,255,.03);
  border-radius: 22px;
  overflow: hidden;
}
.workspace { padding: 16px; }
.modeHint {
  color: var(--muted);
  margin-bottom: 12px;
  font-size: 13px;
  line-height: 1.45;
}
.modePane { min-height: 100%; }

.listGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}
.fuseCard {
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.04));
  border-radius: 18px;
  padding: 14px;
  cursor: pointer;
  color: var(--text);
  text-align: left;
  min-height: 126px;
  transition: transform .14s ease, border-color .14s ease, background .14s ease;
}
.fuseCard:hover {
  transform: translateY(-2px);
  border-color: rgba(96,165,250,.55);
}
.fuseCard.active {
  outline: 2px solid rgba(96,165,250,.6);
  background: rgba(96,165,250,.10);
}
.fuseHead {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 8px;
}
.fuseNo {
  font-size: 28px;
  font-weight: 800;
}
.fuseMeta, .fuseOwners {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}
.badge {
  display: inline-flex;
  margin-top: 10px;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(52,211,153,.14);
  border: 1px solid rgba(52,211,153,.25);
  color: #bbf7d0;
  font-size: 12px;
}
.hiddenBadge {
  background: rgba(248,113,113,.12);
  border-color: rgba(248,113,113,.25);
  color: #fecaca;
  margin-left: 6px;
}

.fuseCard.emptyFuse {
  border-color: rgba(248,113,113,.62);
  background: linear-gradient(180deg, rgba(248,113,113,.12), rgba(255,255,255,.04));
}
.fuseCard.emptyFuse .fuseNo {
  color: var(--state-red);
}
.fuseCard.emptyFuse .badge {
  background: rgba(248,113,113,.16);
  border-color: rgba(248,113,113,.3);
  color: #fee2e2;
}

.fuseCard.partialFuse {
  border-color: rgba(251,191,36,.55);
  background: linear-gradient(180deg, rgba(251,191,36,.12), rgba(255,255,255,.04));
}
.fuseCard.partialFuse .fuseNo {
  color: var(--state-yellow);
}
.fuseCard.partialFuse .badge {
  background: rgba(251,191,36,.16);
  border-color: rgba(251,191,36,.3);
  color: #fef3c7;
}

.fuseCard.fullFuse {
  border-color: rgba(52,211,153,.45);
}
.fuseCard.fullFuse .fuseNo {
  color: var(--state-green);
}

.imageWrap {
  position: relative;
  width: 100%;
  aspect-ratio: 478 / 451;
  border-radius: 18px;
  overflow: hidden;
  background: #0b1220;
  border: 1px solid var(--border);
  user-select: none;
}
.panelImage {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}
.hotspot {
  position: absolute;
  border: 2px solid transparent;
  background: rgba(148,163,184,.10);
  border-radius: 9999px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, transform .12s ease;
  color: transparent;
  padding: 0;
  overflow: visible;
}
.hotspot:hover, .hotspot.active {
  transform: scale(1.03);
}
.hotspot label {
  position: absolute;
  left: 50%;
  top: -1.65em;
  transform: translateX(-50%);
  color: var(--text);
  background: rgba(8,16,31,.90);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  white-space: nowrap;
  pointer-events: none;
}
.hotspot.empty {
  border-color: rgba(248,113,113,.95);
  background: rgba(248,113,113,.28);
}
.hotspot.partial {
  border-color: rgba(251,191,36,.95);
  background: rgba(251,191,36,.24);
}
.hotspot.full {
  border-color: rgba(52,211,153,.95);
  background: rgba(52,211,153,.18);
}
.hotspot.empty:hover, .hotspot.empty.active {
  background: rgba(248,113,113,.36);
}
.hotspot.partial:hover, .hotspot.partial.active {
  background: rgba(251,191,36,.32);
}
.hotspot.full:hover, .hotspot.full.active {
  background: rgba(52,211,153,.26);
}
.hotspot.editing {
  box-shadow: 0 0 0 2px rgba(52,211,153,.25);
}
.resizeHandle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  display: none;
  cursor: nwse-resize;
}
.hotspot.editing .resizeHandle {
  display: block;
}

.editPanel {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(255,255,255,.04);
  padding: 12px 14px;
}
.editPanel h3 { margin: 0 0 8px 0; font-size: 15px; }
.editRow {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 8px 10px;
  align-items: center;
  font-size: 13px;
}
.editRow code {
  background: rgba(255,255,255,.05);
  padding: 3px 6px;
  border-radius: 8px;
}
.editButtons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.smallBtn {
  border: 1px solid var(--border);
  background: rgba(255,255,255,.04);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
}
.smallBtn:hover { background: rgba(255,255,255,.07); }

.details {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.detailsHeader {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.03);
}
.eyebrow {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.detailsHeader h2 {
  margin: 4px 0 6px;
  font-size: 24px;
}
.detailsHeader p {
  margin: 0;
  color: var(--muted);
}
.selectedSummary {
  padding: 14px 18px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.04);
  font-size: 13px;
}
.selectedBody {
  padding: 14px 18px 18px;
  overflow: auto;
}
.ownerBlock {
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  margin-bottom: 14px;
  background: rgba(255,255,255,.03);
}
.ownerHeader {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: rgba(255,255,255,.05);
  font-weight: 700;
}
.ownerBody { overflow-x: auto; }
.loadTable {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}
.loadTable th, .loadTable td {
  text-align: left;
  vertical-align: top;
  padding: 10px 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  font-size: 14px;
}
.loadTable th {
  color: #cbd5e1;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.included td { color: var(--text); }
.excluded td { color: var(--danger); background: rgba(248,113,113,.06); }
.empty {
  color: var(--muted);
  padding: 8px 0 0;
  font-size: 14px;
}

@media (max-width: 1040px) { .app { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .topbar { flex-direction: column; align-items: stretch; }
  .toolbar { justify-content: stretch; }
  .search input { width: 100%; max-width: none; }
  .filepicker { min-width: 0; }
}

.hiddenControl {
  display: none !important;
}

.loadCard {
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.04));
  border-radius: 18px;
  padding: 14px;
  cursor: pointer;
  color: var(--text);
  text-align: left;
  min-height: 126px;
  transition: transform .14s ease, border-color .14s ease, background .14s ease;
}
.loadCard:hover {
  transform: translateY(-2px);
  border-color: rgba(96,165,250,.55);
}
.loadCard.active {
  outline: 2px solid rgba(96,165,250,.6);
  background: rgba(96,165,250,.10);
}
.loadCard .loadTitle {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 8px;
}
.loadCard .loadMeta,
.loadCard .loadFuses {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}
.loadCard.emptyLoad {
  border-color: rgba(248,113,113,.62);
}
.loadCard.partialLoad {
  border-color: rgba(251,191,36,.55);
}
.loadCard.fullLoad {
  border-color: rgba(52,211,153,.45);
}

.loadCard {
  min-height: 160px;
}
.loadExtra {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  margin-top: 3px;
}
@media (max-width: 760px) {
  .loadCard {
    min-height: 150px;
  }
}

.hiddenControl { display: none !important; }
body.compactCards .loadCard { min-height: 130px; }
body.compactCards .fuseCard { min-height: 110px; }

/* v1.7.3: top-align load cards in kuormittain view */
.listGrid {
  align-items: start;
}

.loadCard {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-self: start;
}

/* v1.7.7: fit image fully in the image view */
.imageWrap {
  aspect-ratio: auto;
  height: auto;
}

.panelImage {
  width: 100%;
  height: auto;
  object-fit: contain;
  display: block;
}







/* v1.8.1: larger image at 100% zoom and better mobile loads layout */
.imageWrap {
  position: relative;
  display: inline-block;
  width: fit-content;
  max-width: 100%;
  max-height: min(80vh, calc(100vh - 150px));
  border-radius: 18px;
  overflow: hidden;
  background: #0b1220;
  border: 1px solid var(--border);
  user-select: none;
}

.panelImage {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(80vh, calc(100vh - 150px));
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

@media (max-width: 1040px) {
  .app {
    display: flex;
    flex-direction: column;
  }

  body.mode-loads .details {
    order: -1;
  }

  body.mode-loads .workspace {
    order: 1;
  }

  body.mode-loads .modePane {
    min-height: 0;
  }

  body.mode-loads .listGrid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }
}

@media (max-width: 760px) {
  .imageWrap,
  .panelImage {
    max-height: min(65vh, calc(100vh - 220px));
  }

  body.mode-loads .loadCard {
    min-height: 135px;
  }
}

/* v1.8.2: keep hotspots aligned to the rendered image box */
.imageStage {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.imageWrap {
  position: relative;
  display: block;
  width: 100%;
  max-width: 1280px;
  border-radius: 18px;
  overflow: hidden;
  background: #0b1220;
  border: 1px solid var(--border);
  user-select: none;
}

.panelImage {
  display: block;
  width: 100%;
  height: auto;
  max-height: min(82vh, calc(100vh - 130px));
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.hotspotLayer {
  position: absolute;
  pointer-events: none;
  left: 0;
  top: 0;
}

.hotspotLayer .hotspot {
  pointer-events: auto;
}

@media (max-width: 1040px) {
  .app {
    display: flex;
    flex-direction: column;
  }

  body.mode-loads .details {
    order: -1;
  }

  body.mode-loads .workspace {
    order: 1;
  }

  body.mode-loads .modePane {
    min-height: 0;
  }

  body.mode-loads .listGrid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }
}

@media (max-width: 760px) {
  .panelImage {
    max-height: min(68vh, calc(100vh - 210px));
  }

  body.mode-loads .loadCard {
    min-height: 135px;
  }
}

/* v1.8.3: hotspot layer tied to image box, no separate measurement needed */
.imageStage {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.imageWrap {
  position: relative;
  display: inline-block;
  width: auto;
  max-width: 100%;
  border-radius: 18px;
  overflow: hidden;
  background: #0b1220;
  border: 1px solid var(--border);
  user-select: none;
}

.panelImage {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(82vh, calc(100vh - 120px));
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.hotspotLayer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hotspotLayer .hotspot {
  pointer-events: auto;
}

@media (max-width: 1040px) {
  .app {
    display: flex;
    flex-direction: column;
  }

  body.mode-loads .details {
    order: -1;
  }

  body.mode-loads .workspace {
    order: 1;
  }

  body.mode-loads .listGrid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }
}

@media (max-width: 760px) {
  .panelImage {
    max-height: min(68vh, calc(100vh - 200px));
  }

  body.mode-loads .loadCard {
    min-height: 135px;
  }
}

/* v1.8.4: force image and hotspots to use the same width-based layout */
.imageStage {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.imageWrap {
  position: relative !important;
  display: block !important;
  width: 100% !important;
  max-width: 100% !important;
  aspect-ratio: auto !important;
  height: auto !important;
  border-radius: 18px;
  overflow: hidden;
  background: #0b1220;
  border: 1px solid var(--border);
  user-select: none;
}

.panelImage {
  display: block !important;
  width: 100% !important;
  height: auto !important;
  max-width: 100% !important;
  object-fit: contain !important;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.hotspotLayer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hotspotLayer .hotspot {
  pointer-events: auto;
}

@media (max-width: 1040px) {
  .app {
    display: flex;
    flex-direction: column;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .modeSwitch {
    width: 100%;
    display: flex;
    gap: 6px;
  }

  .modeBtn {
    flex: 1 1 0;
    min-width: 0;
  }

  .toolbar .field,
  .toolbar .actionBtn,
  .toolbar .modeSwitch {
    width: 100%;
  }

  body.mode-loads .details {
    order: -1;
  }

  body.mode-loads .workspace {
    order: 1;
  }

  body.mode-loads .listGrid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }
}

@media (max-width: 760px) {
  .panelImage {
    max-height: min(68vh, calc(100vh - 200px)) !important;
  }

  body.mode-loads .loadCard {
    min-height: 135px;
  }
}


/* v1.8.5: shrink-to-fit image container so hotspots stay aligned */
.imageStage {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.imageWrap {
  position: relative !important;
  display: inline-block !important;
  width: fit-content !important;
  max-width: 100% !important;
  border-radius: 18px;
  overflow: hidden;
  background: #0b1220;
  border: 1px solid var(--border);
  user-select: none;
}

.panelImage {
  display: block !important;
  width: auto !important;
  height: auto !important;
  max-width: 100% !important;
  max-height: min(82vh, calc(100vh - 120px)) !important;
  object-fit: contain !important;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.hotspotLayer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hotspotLayer .hotspot {
  pointer-events: auto;
}

@media (max-width: 1040px) {
  .app {
    display: flex;
    flex-direction: column;
  }

  body.mode-loads .details {
    order: -1;
  }

  body.mode-loads .workspace {
    order: 1;
  }

  body.mode-loads .listGrid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }

  .toolbar {
    justify-content: stretch;
  }

  .modeSwitch {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .modeBtn {
    min-width: 0;
  }
}

@media (max-width: 760px) {
  .panelImage {
    max-height: min(68vh, calc(100vh - 200px)) !important;
  }

  body.mode-loads .loadCard {
    min-height: 135px;
  }

  .toolbar {
    gap: 8px;
  }

  .actionBtn, .modeBtn {
    padding: 10px 10px;
  }
}

/* v1.8.6: stable image layout and always-visible mobile mode buttons */
.imageStage {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.imageWrap {
  position: relative;
  display: inline-block;
  width: fit-content;
  max-width: 100%;
  border-radius: 18px;
  overflow: hidden;
  background: #0b1220;
  border: 1px solid var(--border);
  user-select: none;
}

.panelImage {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(82vh, calc(100vh - 120px));
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.hotspotLayer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hotspotLayer .hotspot {
  pointer-events: auto;
}

@media (max-width: 1040px) {
  .app {
    display: flex;
    flex-direction: column;
  }

  body.mode-loads .details {
    order: -1;
  }

  body.mode-loads .workspace {
    order: 1;
  }

  body.mode-loads .listGrid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }
}

@media (max-width: 900px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar {
    width: 100%;
    justify-content: stretch;
    align-items: stretch;
  }

  .modeSwitch {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .modeBtn {
    min-width: 0;
    padding: 10px 8px;
    font-size: 13px;
  }

  .actionBtn,
  .field,
  .search input,
  .filepicker {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .toolbar .field {
    flex: 1 1 100%;
  }
}

@media (max-width: 760px) {
  .panelImage {
    max-height: min(68vh, calc(100vh - 200px));
  }

  body.mode-loads .loadCard {
    min-height: 135px;
  }
}
