:root {
  color-scheme: light;
  font-family: "Segoe UI", Arial, sans-serif;
  --ink: #17212f;
  --muted: #657386;
  --line: #d8e0ea;
  --panel: #ffffff;
  --soft: #f7f9fc;
  --blue: #1f6feb;
  --blue-dark: #174ea6;
  --red: #a22a2a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.78), rgba(255,255,255,0.36)),
    radial-gradient(circle at 18% 12%, rgba(102, 144, 190, 0.22), transparent 34%),
    #eef2f6;
  color: var(--ink);
}

header {
  height: 134px;
  min-height: 134px;
  padding: 12px 18px;
  display: grid;
  grid-template-columns: minmax(330px, 430px) minmax(0, 1fr);
  column-gap: 18px;
  align-items: center;
  border-bottom: 1px solid rgba(120, 136, 158, 0.22);
  background: rgba(255,255,255,0.76);
  backdrop-filter: blur(12px);
  position: relative;
}

.brand-block {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 2;
}

.brand-logo {
  display: block;
  width: 210px;
  height: auto;
  aspect-ratio: 1380 / 722;
}

.header-right {
  min-width: 0;
  height: 100%;
  align-self: stretch;
  padding-top: 18px;
  display: grid;
  grid-template-rows: auto 1fr;
  align-content: start;
  gap: 8px;
}

.header-tagline {
  color: var(--ink);
  font-family: "Bank Gothic", "Microgramma", "Eurostile Extended", "Arial Narrow", sans-serif;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: 2.2px;
  line-height: 1.1;
  text-transform: uppercase;
  white-space: nowrap;
}

.header-toolbar {
  min-width: 0;
  align-self: end;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-start;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  z-index: 1;
}

#viewerTopActions { justify-content: flex-start; }

.viewer-workflow { width: 100%; }

.workflow {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-start;
  max-width: 100%;
  color: #3d4a5a;
  font-size: 14px;
  white-space: nowrap;
}

.workflow span:not(.toolbar-spacer),
.workflow button,
.workflow select {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 96px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: #3d4a5a;
  font-weight: 650;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
}

.workflow select {
  padding: 0 9px;
  appearance: auto;
}

.workflow #viewSelect {
  width: 132px;
  min-width: 132px;
  flex: 0 0 132px;
  padding-left: 6px;
  padding-right: 4px;
  font-size: 12px;
}

.workflow span:not(.toolbar-spacer) { cursor: default; }

.toolbar-spacer {
  width: 20px;
  height: 32px;
  flex: 0 0 20px;
  pointer-events: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.toolbar-spacer::before {
  content: "\2022";
  color: #111827;
  font-size: 28px;
  line-height: 1;
  font-weight: 800;
}

.workflow button.primary-workflow,
.workflow button.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

#moreBtn { display: none; }

.demo-action-group {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  height: 32px;
}

.workflow .demo-action-group #demoBtn {
  width: 96px;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.workflow .demo-action-group #demoMenuBtn {
  width: 30px;
  min-width: 30px;
  flex: 0 0 30px;
  padding: 0;
  border-left: 0;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.viewer-demo-menu {
  width: min(220px, calc(100vw - 42px));
}

.workflow button:disabled,
.workflow select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.viewer-project-info {
  width: auto !important;
  min-width: 150px;
  max-width: 100%;
  flex: 1 1 180px;
  height: auto !important;
  min-height: 18px;
  padding: 0 10px;
  margin-left: auto;
  border: 0 !important;
  background: transparent !important;
  color: var(--muted);
  font-size: 12px;
  cursor: default !important;
  justify-content: flex-end !important;
  font-weight: 600 !important;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
}

.route-page {
  flex: 1;
  min-height: 0;
  display: none;
  overflow: auto;
  padding: 24px;
}

.route-page.active { display: block; }

#viewerPage {
  padding: 18px;
  height: calc(100vh - 134px);
  overflow: hidden;
}

.viewer-shell {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0;
  overflow: hidden;
}

.toolbar-popovers {
  position: relative;
  min-height: 0;
  z-index: 25;
}

.viewer-popover {
  position: absolute;
  top: 0;
  left: 0;
  width: min(320px, calc(100vw - 42px));
  max-height: min(460px, calc(100vh - 160px));
  overflow: auto;
  display: none;
  padding: 10px;
  border: 1px solid rgba(116, 130, 150, 0.42);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 18px 44px rgba(20, 32, 45, 0.18);
}

.viewer-popover.open { display: grid; gap: 8px; }

.viewer-popover button,
.viewer-popover select,
.viewer-popover input {
  font: inherit;
}

.viewer-popover button {
  min-height: 34px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  color: #243247;
  padding: 7px 9px;
  text-align: left;
  cursor: pointer;
  font-weight: 700;
}

.viewer-popover button:hover,
.viewer-popover button:focus-visible,
.workflow button:focus-visible,
.workflow select:focus-visible {
  outline: 2px solid rgba(31, 111, 235, 0.36);
  outline-offset: 2px;
}

.viewer-popover button.active {
  border-color: var(--blue);
  background: #eff6ff;
  color: var(--blue-dark);
}

.popover-title {
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.popover-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.popover-options {
  display: grid;
  gap: 7px;
}

.restore-button {
  margin-top: 3px;
}

.display-controls {
  display: grid;
  gap: 10px;
}

.display-control {
  display: grid;
  gap: 5px;
  color: #334155;
  font-size: 12px;
  font-weight: 700;
}

.display-control input[type="range"] {
  width: 100%;
}

.display-control input[type="checkbox"] {
  width: auto;
}

.display-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
}

.viewer-content {
  display: grid;
  grid-template-columns: minmax(330px, 430px) minmax(0, 1fr);
  gap: 18px;
  flex: 1;
  min-height: 0;
}

.viewer-sidebar {
  border: 1px solid rgba(129, 144, 164, 0.28);
  background: rgba(255,255,255,0.92);
  border-radius: 8px;
  padding: 14px;
  overflow: auto;
  min-height: 0;
  box-shadow: 0 14px 38px rgba(20, 32, 45, 0.10);
}

.viewer-sidebar-title {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 800;
  color: var(--ink);
}

.viewer-sidebar .notes {
  margin-top: 0;
  border-top: 0;
  padding-top: 0;
}

.viewer-project-info-card {
  margin-top: 8px;
  border: 1px solid rgba(116, 130, 150, 0.35);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  padding: 9px 10px;
  color: #334155;
  font-size: 12px;
  line-height: 1.45;
}

.viewer-project-info-card strong {
  display: block;
  margin-bottom: 5px;
  color: var(--ink);
  font-size: 13px;
}

.viewer-project-info-card .muted {
  color: #64748b;
}

.viewer-stage {
  border: 1px solid rgba(129, 144, 164, 0.28);
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  min-height: 0;
  position: relative;
  box-shadow: 0 14px 38px rgba(20, 32, 45, 0.10);
}

#plotlyHost,
#vtkHost {
  position: absolute;
  inset: 0;
  display: none;
  width: 100%;
  height: 100%;
  min-height: 0;
  background: #fff;
}

.coordinate-hover {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 19;
  display: none;
  min-width: 190px;
  max-width: min(320px, calc(100% - 24px));
  padding: 8px 10px;
  border: 1px solid rgba(71, 85, 105, 0.4);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.16);
  color: #17212f;
  font-size: 12px;
  line-height: 1.35;
  pointer-events: none;
}

.coordinate-hover.active {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 8px;
}

.coordinate-hover b {
  color: #475569;
}

.dynamic-nav {
  display: none;
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 18;
  grid-template-columns: repeat(3, 36px);
  gap: 6px;
  padding: 8px;
  border: 1px solid rgba(30, 42, 58, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.14);
  backdrop-filter: blur(6px);
}

body.dynamic-view .dynamic-nav {
  display: grid;
}

.dynamic-nav button {
  width: 36px;
  height: 32px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  color: #1f2a3d;
  font: inherit;
  font-size: 12px;
  font-weight: 850;
  line-height: 1;
  cursor: pointer;
}

.dynamic-nav button:hover:not(:disabled),
.dynamic-nav button:focus-visible {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.16);
  outline: none;
}

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #667085;
  pointer-events: none;
  padding: 24px;
  background:
    linear-gradient(90deg, rgba(214, 222, 234, 0.34) 1px, transparent 1px),
    linear-gradient(rgba(214, 222, 234, 0.34) 1px, transparent 1px),
    #ffffff;
  background-size: 42px 42px;
}

.empty-card {
  width: min(430px, 90%);
  padding: 24px;
  background: rgba(255,255,255,0.92);
  border: 1px solid #e1e8f1;
  border-radius: 8px;
  box-shadow: 0 14px 34px rgba(20, 32, 45, 0.08);
}

.empty-card strong {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
  font-size: 20px;
}

.error {
  color: var(--red);
  font-weight: 700;
  margin-top: 10px;
}

.notes {
  color: #7a4d00;
  font-size: 13px;
  line-height: 1.4;
}

.viewer-marker-panel {
  margin-top: 8px;
  border: 1px solid rgba(116, 130, 150, 0.35);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  padding: 8px;
  display: none;
}

.viewer-marker-panel.active { display: block; }

.viewer-marker-panel button {
  display: block;
  width: 100%;
  margin-top: 6px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  padding: 7px 8px;
  text-align: left;
  cursor: pointer;
  font-weight: 700;
}

.viewer-marker-panel .marker-note {
  margin: 4px 0 8px;
  padding: 7px 8px;
  border: 1px solid rgba(17, 24, 39, 0.12);
  border-radius: 6px;
  background: rgba(248, 250, 252, 0.96);
  color: #334155;
  font-size: 12px;
  line-height: 1.35;
}

.viewer-marker-panel .muted {
  color: #64748b;
  font-size: 12px;
}

.tool-result {
  display: none;
  margin-top: 10px;
  padding: 8px;
  border: 1px solid rgba(31, 111, 235, 0.22);
  border-radius: 8px;
  background: #f8fbff;
  color: #26364c;
  font-size: 12px;
  line-height: 1.35;
}

.tool-result.active { display: block; }

.tool-dom-overlay {
  position: absolute;
  inset: 0;
  z-index: 18;
  pointer-events: none;
}

.tool-dom-overlay.active {
  pointer-events: none;
}

.tool-dom-overlay.capture {
  cursor: crosshair;
  pointer-events: all;
}

.tool-overlay-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.tool-overlay-line {
  fill: none;
  stroke: #111827;
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 3px rgba(255, 255, 255, 0.86));
}

.tool-overlay-polygon {
  fill: rgba(31, 111, 235, 0.16);
  stroke: #111827;
  stroke-width: 3;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 3px rgba(255, 255, 255, 0.86));
}

.tool-overlay-point {
  fill: #1f6feb;
  stroke: #ffffff;
  stroke-width: 2.5;
  filter: drop-shadow(0 2px 4px rgba(15, 23, 42, 0.32));
  pointer-events: all;
  cursor: grab;
}

.tool-overlay-point.dragging {
  cursor: grabbing;
}

.tool-draft-label {
  position: absolute;
  max-width: 240px;
  padding: 5px 7px;
  border: 1px solid rgba(17, 24, 39, 0.35);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.94);
  color: #17212f;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.14);
  transform: translate(-50%, -110%);
  pointer-events: none;
}

#plotlyHost.tools-active .hoverlayer,
#plotlyHost.tools-active .spikelines,
#plotlyHost.tools-active .hovertext,
body.tools-active .hoverlayer,
body.tools-active .spikelines,
body.tools-active .hovertext {
  display: none !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

#plotlyHost.tools-active,
#plotlyHost.tools-active * {
  cursor: crosshair !important;
}

.created-link {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid rgba(129, 144, 164, 0.24);
  font-size: 12px;
  font-weight: 700;
}

.created-link a {
  color: var(--blue);
  text-decoration: none;
}

.creator-attribution {
  margin-top: 8px;
  color: #526174;
  font-size: 12px;
  line-height: 1.4;
  font-weight: 600;
}

.creator-attribution a {
  font-weight: 700;
}

.viewer-policy-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 8px;
  font-weight: 600;
}

.viewer-policy-links a {
  color: #475569;
}

.created-link a:hover {
  text-decoration: underline;
}

@media (max-width: 980px) {
  header {
    height: auto;
    min-height: 0;
    padding: 8px 10px;
    grid-template-columns: 1fr;
    gap: 6px;
    align-items: center;
  }

  .brand-logo {
    width: min(176px, 58vw);
  }

  .header-right {
    height: auto;
    padding-top: 0;
    gap: 6px;
  }

  .header-tagline {
    display: none;
  }

  .workflow {
    flex-wrap: wrap;
    white-space: normal;
    justify-content: center;
    gap: 6px;
  }

  .top-actions {
    width: 100%;
    justify-content: center;
  }

  .viewer-project-info {
    display: none !important;
  }

  .toolbar-spacer { display: none; }

  #toolsBtn,
  #paletteBtn,
  #shotBtn {
    display: none;
  }

  #moreBtn {
    display: inline-flex;
  }

  body {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .viewer-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  #viewerPage {
    height: auto;
    min-height: 0;
    overflow: visible;
    padding: 10px;
  }

  .viewer-shell {
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  .viewer-stage {
    order: 1;
    height: min(68vh, 560px);
    min-height: 360px;
  }

  .viewer-sidebar {
    order: 2;
    overflow: visible;
  }

  .viewer-popover {
    width: min(340px, calc(100vw - 20px));
    max-height: min(520px, calc(100vh - 120px));
  }
}

@media (min-width: 981px) and (max-width: 1500px) {
  .workflow { gap: 4px; }

  .viewer-project-info {
    flex-basis: 100%;
    margin-left: 0;
    justify-content: flex-start !important;
    text-align: left;
  }

  .workflow span:not(.toolbar-spacer),
  .workflow button,
  .workflow select {
    width: 74px;
    font-size: 12px;
  }

  .toolbar-spacer {
    width: 10px;
    flex-basis: 10px;
  }
}

@media (min-width: 981px) and (max-width: 1300px) {
  .workflow {
    gap: 3px;
  }

  .workflow span:not(.toolbar-spacer),
  .workflow button,
  .workflow select {
    width: 68px;
    padding-left: 5px;
    padding-right: 5px;
    font-size: 11px;
  }

  .toolbar-spacer {
    display: none;
  }
}

@media (min-width: 981px) and (max-width: 1500px) {
  .workflow .demo-action-group #demoBtn {
    width: 74px;
    font-size: 12px;
  }

  .workflow .demo-action-group #demoMenuBtn {
    width: 30px;
    min-width: 30px;
    flex-basis: 30px;
    padding: 0;
  }
}

@media (min-width: 981px) and (max-width: 1300px) {
  .workflow .demo-action-group #demoBtn {
    width: 68px;
    padding-left: 5px;
    padding-right: 5px;
    font-size: 11px;
  }

  .workflow .demo-action-group #demoMenuBtn {
    width: 26px;
    min-width: 26px;
    flex-basis: 26px;
  }
}

.media-list {
  display: grid;
  gap: 8px;
}

.media-item {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  border: 1px solid rgba(116, 130, 150, 0.35);
  border-radius: 7px;
  background: #fff;
  padding: 7px;
}

.media-thumb {
  width: 54px;
  height: 42px;
  border-radius: 5px;
  object-fit: cover;
  border: 1px solid #d7dde6;
  background: #eef2f7;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
  color: #475569;
}

.media-item-title {
  font-weight: 800;
  color: #17212f;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.media-item-meta {
  color: #657386;
  font-size: 11px;
  margin-top: 2px;
}

.media-item button {
  margin-top: 6px;
  min-height: 28px;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  background: #fff;
  color: #243247;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.media-dialog {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.34);
}

.media-dialog.active { display: flex; }

.media-dialog-card {
  width: min(940px, calc(100vw - 36px));
  max-height: calc(100vh - 36px);
  overflow: auto;
  border: 1px solid rgba(101, 116, 139, 0.34);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 22px 70px rgba(20, 32, 45, 0.24);
  padding: 14px;
}

.media-dialog-card h2 {
  margin: 0 0 10px;
  font-size: 18px;
}

.media-viewer-body {
  min-height: 160px;
  max-height: 68vh;
  overflow: auto;
  display: grid;
  place-items: center;
  border: 1px solid #d7dde6;
  border-radius: 7px;
  background: #f8fafc;
  padding: 10px;
}

.media-viewer-body img {
  max-width: 100%;
  height: auto;
  border: 1px solid #d7dde6;
  border-radius: 6px;
  background: #fff;
}

.media-dialog-actions,
.media-pdf-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  margin-top: 10px;
}

.media-pdf-controls {
  justify-content: center;
  margin: 0 0 8px;
  color: #334155;
  font-size: 12px;
}

.media-dialog-actions button,
.media-pdf-controls button {
  min-height: 32px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  color: #243247;
  padding: 6px 9px;
  font-weight: 700;
  cursor: pointer;
}

.media-dialog-actions button.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}
