:root { --nav-offset: 96px; }

.topbar {
  --header-label-size: 20px;
  grid-template-columns: auto auto minmax(0, 1fr) auto minmax(120px, 160px);
  grid-template-areas: "brand title search tabs progress";
  gap: 8px 10px;
  padding: 8px 16px;
}

.topbar .brand { grid-area: brand; }
.topbar .brand strong { font-size: var(--header-label-size); }
.topbar .topnav { grid-area: tabs; justify-content: center; flex-wrap: wrap; }
.topbar .progress-box { grid-area: progress; }
.header-title { grid-area: title; min-width: 0; }
.topbar .search-wrap { grid-area: search; width: 100%; min-width: 0; margin: 0; }
.topbar .search { height: 38px; }
.topbar .search-results { top: calc(100% + 5px); max-height: 50dvh; overflow: auto; }
html { overflow: clip; overscroll-behavior: none; }

body {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: clip;
}

main {
  min-height: 0;
  padding-block: 12px;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
}

.workspace { min-height: 0; align-items: stretch; }
.workspace > * { min-height: 0; }
.workspace .detail,
#gantt-display,
.steps-view {
  overflow: auto;
  overscroll-behavior: contain;
}

.workspace .detail { max-height: none; }
.workspace.gantt-mode .detail { position: static; }
.workspace .map-panel,
#map-display {
  display: flex;
  flex-direction: column;
}

#map-display,
#gantt-display { flex: 1 1 auto; min-height: 0; }
.workspace .viewport { flex: 1 1 auto; min-height: 0; height: auto; }
.map-head, .map-footer { flex: none; }
.steps-view { width: 100%; }
.library-disclaimer { margin: 5px 0 0; color: var(--muted); font-size: 13px; }

.journey-column {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.gantt-mode .journey-column { display: none; }
.journey-column .journey { flex: 1 1 auto; min-height: 0; }

@media (min-width: 961px) {
  .journey-column { container: journey / size; }
}

@container journey (max-height: 780px) {
  .journey .side-head { padding-block: 10px 7px; }
  .journey .phase-button { min-height: 40px; padding-block: 3px; }
  .journey .legend { margin-top: 7px; padding-block: 7px; gap: 3px; }
  .journey .local-note { padding-block: 6px; }
}

@container journey (max-width: 210px) and (max-height: 730px) {
  .journey .phase-button small { display: none; }
}

@container journey (max-width: 210px) and (max-height: 620px) {
  .journey .local-note { display: none; }
}

@container journey (max-height: 550px) {
  .journey .legend,
  .journey .local-note { display: none; }
}

@container journey (max-height: 500px) {
  .journey .phase-button { min-height: 29px; padding-block: 1px; }
  .journey .phase-button small { display: none; }
}

@container journey (max-height: 345px) {
  .journey #phases {
    grid-auto-flow: column;
    grid-auto-columns: minmax(140px, 1fr);
    overflow-x: auto;
    padding-bottom: 7px;
  }
}

.feedback-button {
  flex: none;
  align-self: stretch;
  padding: 4px 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: #a61b1b;
  font-size: 12px;
}

.feedback-button:hover { background: #fff1f1; }

.atlas-release {
  flex: none;
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
  text-align: center;
}

#feedback-dialog { width: min(440px, calc(100% - 28px)); }
.feedback-body {
  padding: 14px 17px 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.feedback-body p { margin: 0; }
.feedback-notices { margin: 10px 0 0; padding-inline-start: 20px; }
.feedback-notices li + li { margin-top: 6px; }

.header-title h1 {
  margin: 0;
  color: var(--muted);
  font-size: var(--header-label-size);
  font-weight: 600;
  letter-spacing: -.025em;
}

.header-title h1 em { color: inherit; }

.edition-link {
  display: inline-block;
  margin-top: 2px;
  color: #2b50c7;
  font-size: 12px;
  font-weight: 650;
  text-decoration: none;
}

.edition-link:hover {
  text-decoration: underline;
}

.context-references {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  margin: 7px 0 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.context-references a { text-underline-offset: 2px; overflow-wrap: anywhere; }

@media (max-width: 960px) {
  .workspace { overflow: auto; overscroll-behavior: contain; align-content: start; }
  .workspace:not(.gantt-mode) { grid-template-rows: max-content; }
  .journey-column { align-self: start; }
  .journey-column .journey { flex: none; }
  .workspace .detail, #gantt-display { overflow: visible; }
  .workspace .viewport { flex: none; height: clamp(250px, 55dvh, 550px); }
  .workspace .map-panel, .workspace .detail { scroll-margin: 4px; }
}

@media (max-width: 1180px) {
  :root { --nav-offset: 132px; }
  .topbar {
    grid-template-columns: auto auto minmax(0, 1fr) minmax(120px, 160px);
    grid-template-areas: "brand title search progress" "tabs tabs tabs tabs";
  }
}

@media (max-width: 640px) {
  :root { --nav-offset: 176px; }
  .topbar {
    --header-label-size: 17px;
    grid-template-columns: auto minmax(0, 1fr) minmax(120px, 40%);
    grid-template-areas: "brand title title" "search search progress" "tabs tabs tabs";
    gap: 6px 10px;
    padding-inline: 12px;
  }
  .topbar .search { padding-inline: 8px; gap: 5px; }
  .topbar .search kbd { display: none; }
  .topbar .topnav { gap: 2px; }
  .topbar .topnav button { gap: 4px; padding: 8px 5px; font-size: 12px; }
}

@media (max-width: 380px) {
  .topbar .topnav svg { display: none; }
}

#progress-backup {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 5px 7px;
  font-size: 11px;
}

.stage-note {
  display: grid;
  gap: 5px;
  margin-top: 12px;
  color: #24395d;
}

.stage-note textarea {
  width: 100%;
  padding: 8px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: white;
  color: inherit;
  font: inherit;
}

.node-copy strong,
.gantt-scroll th button strong,
.step-card > summary > :first-child {
  min-width: 0;
}

.stage-title-text,
.gantt-scroll th button .stage-title-text {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  white-space: nowrap;
}

[data-note-preview]:has(> .note-marker:not([hidden])) > .stage-title-text {
  max-width: calc(100% - 1.3em);
}

.note-marker {
  display: inline-block;
  width: .9em;
  height: .9em;
  margin-inline-start: .35em;
  border: 1px solid #2156a6;
  border-radius: 2px;
  background: linear-gradient(#2156a6,#2156a6) center 35% / 55% 1px no-repeat,
              linear-gradient(#2156a6,#2156a6) center 65% / 55% 1px no-repeat, #eef4ff;
}

.note-preview {
  position: fixed;
  z-index: 20;
  width: max-content;
  max-width: min(310px, calc(100vw - 16px), var(--note-width, 310px));
  padding: 8px 11px;
  border: 1px solid #405474;
  border-radius: 8px;
  background: #172745;
  color: #fff;
  box-shadow: 0 6px 18px #18264135;
  font-size: 12px;
  line-height: 1.45;
}

.note-preview::before {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  border: 1px solid #405474;
  background: inherit;
  pointer-events: none;
}

.note-preview[data-side="right"]::before {
  top: var(--note-arrow);
  left: 0;
  transform: translate(-50%, -50%) rotate(45deg);
  border-right: 0;
  border-top: 0;
}

.note-preview[data-side="left"]::before {
  top: var(--note-arrow);
  right: 0;
  transform: translate(50%, -50%) rotate(45deg);
  border-left: 0;
  border-bottom: 0;
}

.note-preview[data-side="bottom"]::before {
  top: 0;
  left: var(--note-arrow);
  transform: translate(-50%, -50%) rotate(45deg);
  border-right: 0;
  border-bottom: 0;
}

.note-preview[data-side="top"]::before {
  bottom: 0;
  left: var(--note-arrow);
  transform: translate(-50%, 50%) rotate(45deg);
  border-left: 0;
  border-top: 0;
}

@media (pointer: coarse) {
  .note-marker {
    position: relative;
    vertical-align: middle;
  }

  .note-marker::after {
    content: "";
    position: absolute;
    inset: -7px;
  }
}

.note-preview p {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 6;
  overflow: hidden;
  margin: 3px 0 0;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.stage-note small, .backup-body, .backup-header p:not(.eyebrow) {
  color: var(--muted);
}

#backup-dialog {
  width: min(760px, 100% - 28px);
  border-radius: 16px;
}

.backup-header {
  align-items: flex-start;
  gap: 12px;
  padding: 18px 20px;
}

.backup-header p:not(.eyebrow) {
  margin: 5px 0 0;
  font-size: 13px;
}

.backup-body {
  padding: 18px 20px;
  font-size: 14px;
}

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

.backup-card {
  --backup-accent: #2b50c7;
  --backup-tint: #edf2ff;
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f9fbff;
}

.backup-card-restore {
  --backup-accent: #08665f;
  --backup-tint: #e4f5f2;
  background: #f7fcfb;
}

.backup-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  color: var(--backup-accent);
  background: var(--backup-tint);
  border-radius: 10px;
}

.backup-icon svg { width: 22px; height: 22px; }
.backup-card h3 { margin: 10px 0 5px; color: #182641; font-size: 17px; }
.backup-card p { margin: 0 0 12px; line-height: 1.45; }
.backup-card .backup-feedback { margin: 8px 0 0; }
.backup-feedback:empty { margin: 0; }

.backup-button {
  padding: 8px 11px;
  background: var(--backup-accent);
  color: white;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 650;
}

.backup-button:hover { filter: brightness(.92); }
.backup-file-label { display: block; margin-bottom: 5px; font-weight: 650; color: #24395d; }
.backup-card input[type="file"] { display: block; width: 100%; font-size: 12px; }
.backup-card input::file-selector-button {
  margin-right: 7px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: white;
  color: var(--backup-accent);
  cursor: pointer;
}

.backup-confirm {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid #eed8ae;
  border-radius: 8px;
  background: #fff9ef;
  color: #6b430e;
}

.backup-privacy {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin: 12px 0 0;
  font-size: 12px;
}

.backup-privacy svg { flex: none; width: 14px; height: 14px; }

.backup-feedback {
  color: #24395d;
  font-weight: 650;
}

.stage-confirmation { width: min(450px, calc(100% - 28px)); }
.stage-confirm-body { padding: 16px; color: var(--muted); }
.stage-confirm-body p { margin: 0 0 12px; line-height: 1.5; }
.stage-confirm-linked { color: #6b430e; }
.stage-confirm-body form { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.stage-confirm-body .stage-confirm-apply { background: #3457d3; border-color: #3457d3; color: white; }
.stage-confirm-body .stage-confirm-apply:hover { background: #2647bb; }

@media (max-width: 580px) {
  .backup-grid { grid-template-columns: minmax(0, 1fr); }
  .backup-header, .backup-body { padding: 14px; }
}
