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

:root {
  color-scheme: light;
  /* Nottingham West PCN / MyMedInfo brand palette */
  --ink: #212b32;
  --muted: #4c6272;
  --line: #d8dde0;
  --panel: #ffffff;
  --page: #f4f8fc;
  --primary: #005eb8;
  --primary-dark: #003a73;
  --primary-tint: #eef7ff;
  --primary-soft: #d6e8f7;
  --danger: #d5281b;
  --good: #007f3b;
  --warn: #8a5b00;
  --focus: #ffeb3b;
  --pcn-blue-deep: #0a2d5e;
  --pcn-green: #6dbe45;
  --header-bg: #d8efff;
  --header-ink: #003d78;
  --header-line: #7fb9e6;
  --hotspot: #ffc857;
  --hotspot-border: #111827;
  --shadow: 0 10px 30px rgba(16, 32, 51, 0.07);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  margin: 0;
  overflow: hidden;
  background: var(--page);
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  display: flex;
  flex: 0 0 auto;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--header-line);
  background: var(--header-bg);
  color: var(--header-ink);
  padding: 12px 22px;
}

.topbar h1 {
  color: var(--pcn-blue-deep);
  font-weight: 800;
  letter-spacing: -0.01em;
}

.topbar h1 span {
  color: var(--pcn-green);
}

.topbar p {
  color: var(--header-ink);
  opacity: 0.85;
}

header h1,
.panel h2,
.panel h3 {
  margin: 0;
}

header h1 {
  font-size: clamp(1.35rem, 2vw, 2rem);
}

.topbar p {
  max-width: 980px;
  margin: 6px 0 0;
  color: var(--muted);
}

.topbarMeta {
  align-self: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.topbarActions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbarActions > button {
  min-height: 34px;
  padding: 6px 12px;
}

.viewSwitch {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.viewSwitch button {
  min-height: 34px;
  border: 0;
  border-radius: 0;
  background: #fff;
  color: var(--ink);
}

.viewSwitch button + button {
  border-left: 1px solid var(--line);
}

.viewSwitch button.active {
  background: var(--primary);
  color: #fff;
}

.viewSwitch button.active:hover {
  background: var(--primary-dark);
}

.userShell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 16px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  padding: 16px;
}

.userShell[hidden],
.appShell[hidden] {
  display: none;
}

.userRail {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.toggleRow {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0 0;
  font-weight: 700;
}

.toggleRow input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  flex: 0 0 auto;
}

.toggleRow .small {
  font-weight: 400;
}

.appShell {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  padding: 16px;
}

.projectBar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 8px 12px;
}

.projectBar label {
  margin: 0;
  color: var(--muted);
}

.projectBar select {
  width: auto;
  min-width: 180px;
  flex: 0 1 320px;
}

.projectBar button {
  min-height: 32px;
  padding: 6px 12px;
}

.projectBar .autosave {
  margin: 0 0 0 auto;
  padding-left: 8px;
}

.projectBar .signout {
  min-height: 32px;
  padding: 6px 12px;
  color: var(--muted);
}

.editorMain {
  display: grid;
  grid-template-columns: minmax(480px, 1fr) minmax(340px, 420px);
  gap: 16px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel > h2 {
  flex: 0 0 auto;
  border-bottom: 1px solid var(--line);
  background: #f8fbfd;
  color: var(--primary-dark);
  padding: 12px 14px;
  font-size: 1rem;
  font-weight: 700;
}

.body {
  padding: 14px;
}

/* Inner scroll regions so columns stay within the viewport */
.userRail .body,
.editorBody {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

label {
  display: block;
  margin: 12px 0 6px;
  color: #2d3748;
  font-weight: 700;
  font-size: 0.86rem;
}

input,
select,
textarea,
button {
  font: inherit;
}

input[type="text"],
input[type="number"],
input[type="password"],
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="password"]:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
}

input[type="file"] {
  width: 100%;
  border: 1px dashed var(--header-line);
  border-radius: 8px;
  padding: 10px;
  background: var(--primary-tint);
}

textarea {
  min-height: 110px;
  resize: vertical;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease, opacity 150ms ease;
}

button:hover {
  border-color: var(--primary);
  background: var(--primary-tint);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

button.primary,
button.good,
button.danger,
button.active {
  border-color: transparent;
  color: #fff;
}

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

button.primary:hover,
button.active:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

button.good {
  background: var(--good);
  border-color: var(--good);
}

button.good:hover {
  opacity: 0.9;
}

button.danger {
  background: var(--danger);
  border-color: var(--danger);
}

button.danger:hover {
  opacity: 0.9;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

hr {
  height: 1px;
  margin: 16px 0;
  border: 0;
  background: var(--line);
}

.row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.top-gap {
  margin-top: 16px;
}

.small {
  color: var(--muted);
  font-size: 0.82rem;
}

.autosave {
  min-height: 20px;
  margin-top: 9px;
  color: var(--muted);
  font-size: 0.82rem;
}

.notice {
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  background: var(--primary-tint);
  padding: 12px 14px;
  color: var(--ink);
}

.kbd {
  display: inline-block;
  border: 1px solid #c6cbd4;
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #fff;
  padding: 0 5px;
  color: #253044;
  font-size: 0.78rem;
}

.list {
  display: grid;
  gap: 8px;
  max-height: 300px;
  overflow: auto;
  padding-right: 3px;
}

.hotspotItem {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 11px;
  text-align: left;
  transition: border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.hotspotItem:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
}

.hotspotItem.is-selected {
  border-color: var(--primary);
  background: var(--primary-tint);
}

.hotspotItem strong {
  display: block;
  overflow-wrap: anywhere;
}

.hotspotItem span {
  color: var(--muted);
  font-size: 0.79rem;
}

.pill {
  align-self: start;
  border-radius: 999px;
  background: #17202a;
  color: #fff;
  padding: 2px 7px;
  font-size: 0.72rem;
  font-weight: 700;
}

.viewerPanel,
.canvasPanel,
.editorPanel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.viewerChrome {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

.viewerFrameWrap {
  flex: 1;
  min-height: 0;
  background: #e9edf3;
}

.viewerFrameWrap iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.modalBackdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.48);
  z-index: 30;
}

.modalBackdrop.hidden {
  display: none;
}

.modalCard {
  width: min(440px, 100%);
}

.modalCard h2 {
  border-bottom: 1px solid var(--line);
  background: #f9fafb;
  padding: 12px 14px;
  font-size: 1rem;
}

.editorBody {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.canvasToolbar,
.viewerToolbar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: #f9fafb;
}

.toolbar button,
.canvasToolbar button,
.viewerToolbar button {
  min-height: 34px;
}

.canvasStatus {
  margin-left: auto;
  white-space: nowrap;
}

.canvasTip {
  position: fixed;
  z-index: 25;
  display: none;
  width: min(360px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  background: #fff;
  padding: 16px;
  box-shadow: 0 16px 36px rgba(16, 32, 51, 0.18);
  pointer-events: none;
}

.canvasTip.show {
  display: block;
}

.canvasTip h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.canvasTip p {
  margin: 0;
  color: #2d3748;
  white-space: pre-wrap;
}

.canvasTip .tipMeta {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.85rem;
}

.stageWrap {
  position: relative;
  flex: 1;
  min-height: 520px;
  overflow: auto;
  background:
    linear-gradient(45deg, #edf0f5 25%, transparent 25%),
    linear-gradient(-45deg, #edf0f5 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #edf0f5 75%),
    linear-gradient(-45deg, transparent 75%, #edf0f5 75%);
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
  cursor: crosshair;
}

.stageWrap.is-panning {
  cursor: grab;
}

.stageWrap.is-panning.dragging {
  cursor: grabbing;
}

.stage {
  position: relative;
  width: 100%;
  min-height: 100%;
  transform-origin: top left;
}

.stage.has-image {
  width: max-content;
  min-width: 0;
  min-height: 0;
}

.stage img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
}

.placeholder {
  display: grid;
  min-height: 520px;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.placeholder h2 {
  margin: 0 0 6px;
  color: #263242;
}

.hotspotBox {
  position: absolute;
  border: 2px dashed rgba(17, 24, 39, 0.4);
  background: rgba(255, 200, 87, 0.08);
  cursor: pointer;
}

.hotspotBox:hover,
.hotspotBox.selected,
.hotspotBox.drawing {
  border-color: var(--hotspot-border);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.92), 0 10px 30px rgba(0, 0, 0, 0.16);
}

.hotspotBox.selected {
  cursor: move;
}

.hotspotBox .hotspotLabel {
  position: absolute;
  top: -28px;
  left: -2px;
  display: none;
  max-width: min(280px, 80vw);
  overflow: hidden;
  border-radius: 5px;
  background: #111827;
  color: #fff;
  padding: 4px 8px;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 700;
}

.hotspotBox:hover .hotspotLabel,
.hotspotBox.selected .hotspotLabel {
  display: block;
}

.resizeHandle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--primary);
  cursor: nwse-resize;
}

.hotspotBox.selected .resizeHandle {
  display: block;
}

.coord {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.coord label {
  margin-top: 10px;
}

.emptyState {
  color: var(--muted);
  font-size: 0.86rem;
}

@media (max-width: 1180px) {
  /* Not enough width for fixed columns — fall back to natural page scrolling */
  body {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .appShell,
  .userShell,
  .editorMain {
    min-height: 0;
    overflow: visible;
  }

  .userRail .body,
  .editorBody {
    overflow-y: visible;
  }

  .viewerPanel {
    min-height: 70vh;
  }
}

@media (max-width: 820px) {
  .topbar {
    flex-direction: column;
  }

  .topbarActions {
    width: 100%;
    justify-content: space-between;
  }

  .editorMain,
  .userShell {
    grid-template-columns: 1fr;
  }

  .stageWrap {
    min-height: 420px;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar button {
    flex: 1 1 140px;
  }
}

button.toggleSection {
  background: none;
  border: none;
  padding: 8px 0;
  margin: 8px 0;
  color: var(--primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
}

button.toggleSection:hover {
  text-decoration: underline;
}

#metaSection.hidden {
  display: none;
}

.publishToggleBar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
}

.publishToggleBar input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}

.publishToggleBar span {
  font-weight: 500;
  color: var(--muted);
}

.projectBar .titleInput {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: var(--ink);
  font-size: 13px;
  font-family: inherit;
  min-width: 180px;
}

.projectBar .titleInput::placeholder {
  color: var(--muted);
}

.panelTabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  background: var(--page);
  gap: 0;
}

.panelTab {
  flex: 1;
  padding: 10px 12px;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 150ms ease;
}

.panelTab:hover {
  color: var(--ink);
  background: rgba(0, 0, 0, 0.02);
}

.panelTab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.panelView {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  background: var(--panel);
  color: var(--ink);
}

.panelView > .body {
  padding: 14px;
  color: var(--ink);
}

.panelView h2 {
  flex: 0 0 auto;
  border-bottom: 1px solid var(--line);
  background: #f8fbfd;
  color: var(--primary-dark);
  padding: 12px 14px;
  margin: 0;
}

.panelView.hidden {
  display: none;
}
