/* System Map — standard theme uses platform tokens; Programme Cream is opt-in (ThemeSettings). */

.system-map-page {
  --sm-accent: var(--primary);
  --sm-accent-tint: color-mix(in srgb, var(--primary) 14%, var(--card));
  --sm-accent-soft: color-mix(in srgb, var(--primary) 12%, var(--card));
  --sm-accent-soft-border: color-mix(in srgb, var(--primary) 40%, var(--border));
  --sm-page: var(--background);
  --sm-warm: var(--background);
  --sm-card: var(--card);
  --sm-sunken: color-mix(in srgb, var(--muted) 40%, var(--card));
  --sm-heading: var(--foreground);
  --sm-body: var(--foreground);
  --sm-muted: var(--muted-foreground);
  --sm-faint: color-mix(in srgb, var(--muted-foreground) 72%, transparent);
  --sm-charcoal: var(--foreground);
  --sm-charcoal-700: color-mix(in srgb, var(--foreground) 88%, black);
  --sm-hub-fill: #585555;
  --sm-green: #16a34a;
  --sm-green-100: color-mix(in srgb, #16a34a 18%, var(--card));
  --sm-red: var(--destructive, #dc2626);
  --sm-red-100: color-mix(in srgb, var(--destructive, #dc2626) 14%, var(--card));
  --sm-neutral-100: var(--muted);
  --sm-neutral-200: color-mix(in srgb, var(--muted) 65%, var(--border));
  --sm-neutral-300: var(--border);
  --sm-border-subtle: var(--border);
  --sm-border-strong: color-mix(in srgb, var(--border) 55%, var(--foreground));
  --sm-shadow-card: var(--shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.05));
  --sm-radius-xl: 14px;
  --sm-radius-2xl: 18px;
  --sm-font: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--background);
  font-family: var(--sm-font);
}

/* User Settings → Theme → Programme Cream (`themePreset: programme`) */
html.theme-programme:not(.dark) .system-map-page {
  --sm-accent: #f6961d;
  --sm-accent-tint: color-mix(in oklch, #f6961d 14%, #fffdfa);
  --sm-accent-soft: color-mix(in oklch, #f6961d 12%, #fffdfa);
  --sm-accent-soft-border: #fbd9ac;
  --sm-page: #fdf7ef;
  --sm-warm: #faf3e9;
  --sm-card: #fffdfa;
  --sm-sunken: #f7f4ef;
  --sm-heading: #2a2018;
  --sm-body: #3a2e22;
  --sm-muted: #7a6f63;
  --sm-faint: #a8967f;
  --sm-charcoal: #3a2e22;
  --sm-charcoal-700: #3d3d3d;
  --sm-hub-fill: #585555;
  --sm-neutral-100: #f5f0e8;
  --sm-neutral-200: #e8e4de;
  --sm-neutral-300: #d6d3d1;
  --sm-border-subtle: #f0e4d4;
  --sm-border-strong: #c9c2b8;
  --sm-shadow-card: 0 1px 2px rgba(42, 32, 24, 0.04), 0 8px 24px rgba(42, 32, 24, 0.06);
  background: #fdf7ef;
}

.system-map-content {
  flex: 1;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 40px 60px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

@media (max-width: 768px) {
  .system-map-content {
    padding: 20px 16px 48px;
  }
}

/* Stats row */
.system-map-stat {
  background: var(--sm-card);
  border: 1px solid var(--sm-border-subtle);
  border-radius: var(--sm-radius-xl);
  box-shadow: var(--sm-shadow-card);
  padding: 20px 22px;
}

.system-map-stat__label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sm-muted);
}

.system-map-stat__value {
  margin-top: 10px;
  font-size: 1.65rem;
  font-weight: 700;
  line-height: 1;
  color: var(--sm-accent);
}

.system-map-stat__sub {
  margin-top: 7px;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--sm-muted);
}

/* Map panel */
.system-map-panel {
  background: var(--sm-card);
  border: 1px solid var(--sm-border-subtle);
  border-radius: var(--sm-radius-2xl);
  box-shadow: var(--sm-shadow-card);
}

.system-map-panel--map {
  padding: 26px 26px 18px;
}

.system-map-panel__eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sm-muted);
}

.system-map-panel__hint {
  margin-top: 8px;
  font-size: 0.875rem;
  font-style: italic;
  line-height: 1.4;
  color: var(--sm-faint);
}

.system-map-panel__header {
  display: flex;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 6px;
}

.system-map-panel__header-main {
  flex: 1;
  min-width: 0;
}

.system-map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding-top: 6px;
  flex: 0 0 auto;
}

.system-map-legend__item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 500;
  color: var(--sm-muted);
}

.system-map-legend-swatch {
  width: 22px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid;
  flex-shrink: 0;
}

.system-map-legend--pending {
  background: var(--sm-neutral-100);
  border-color: var(--sm-neutral-300);
}

.system-map-legend--progress {
  background: var(--sm-accent-tint);
  border-color: var(--sm-accent);
}

.system-map-legend--behind {
  background: var(--sm-red-100);
  border-color: var(--sm-red);
}

.system-map-legend--built {
  background: var(--sm-card);
  border-color: var(--sm-green);
}

/* Diagram stage — scales to fit content width (no clipping) */
.system-map-stage-wrap {
  width: 100%;
  margin-top: 4px;
}

.system-map-stage {
  position: relative;
  width: 100%;
  margin: 0 auto;
  overflow: visible;
}

.system-map-stage__inner {
  position: absolute;
  top: 0;
  left: 50%;
  width: 1160px;
  height: 720px;
  transform-origin: top center;
}

.system-map-stage__svg {
  position: absolute;
  inset: 0;
  width: 1160px;
  height: 720px;
  pointer-events: none;
}

.system-map-stage__svg circle,
.system-map-stage__svg line {
  transition:
    stroke-dasharray 0.7s cubic-bezier(0.4, 0, 0.2, 1),
    stroke-dashoffset 0.7s cubic-bezier(0.4, 0, 0.2, 1),
    stroke 0.35s ease,
    stroke-width 0.35s ease;
}

@keyframes system-map-block-enter {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.system-map-block {
  animation: system-map-block-enter 0.45s cubic-bezier(0.4, 0, 0.2, 1) both;
  position: absolute;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  padding: 7px 10px;
  width: 176px;
  min-height: 76px;
  height: 76px;
  overflow: hidden;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  font-family: var(--sm-font);
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  background: var(--sm-card);
  border: 1px dashed var(--sm-neutral-300);
}

.system-map-block--built {
  border-style: solid;
  border-color: var(--sm-border-strong);
  box-shadow: var(--sm-shadow-card);
}

.system-map-block--selected {
  background: var(--sm-accent-tint);
  border-color: var(--sm-accent);
  border-style: solid;
  box-shadow: var(--sm-shadow-card);
}

.system-map-block--hot:not(.system-map-block--selected) {
  background: color-mix(in oklch, var(--sm-neutral-200) 45%, white);
}

.system-map-block--pending {
  border-style: dashed;
}

.system-map-block__dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  flex-shrink: 0;
}

.system-map-block__dot--built {
  background: var(--sm-green);
}

.system-map-block__dot--partial {
  background: var(--sm-accent);
}

.system-map-block__dot--idle {
  background: var(--sm-neutral-300);
}

.system-map-block__label {
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.system-map-block__label--hot {
  color: var(--sm-charcoal);
}

.system-map-block__label--idle {
  color: var(--sm-muted);
}

.system-map-block__count {
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1;
}

.system-map-block__count--filled {
  color: #292524;
}

.system-map-block__count--empty {
  color: var(--sm-faint);
}

.system-map-block__metrics {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding-left: 15px;
  min-width: 0;
}

.system-map-block__unit {
  font-size: 10px;
  font-weight: 500;
  line-height: 1.2;
  color: var(--sm-faint);
  max-width: 100%;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.system-map-cluster-btn {
  position: absolute;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  text-align: center;
  font-family: var(--sm-font);
  font-weight: 600;
  font-size: 0.9375rem;
  line-height: 1.35;
}

.system-map-cluster-label--hot {
  color: var(--sm-heading);
}

.system-map-cluster-label--idle {
  color: var(--sm-muted);
}

.system-map-cluster-pct {
  position: absolute;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}

.system-map-cluster-pct--done {
  color: var(--sm-accent);
}

.system-map-cluster-pct--idle {
  color: var(--sm-faint);
}

.system-map-pill {
  position: absolute;
  height: 30px;
  width: 104px;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--sm-font);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border: 1px solid;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.system-map-pill--built {
  background: var(--sm-accent-soft);
  border-color: var(--sm-accent-soft-border);
  color: var(--sm-accent);
}

.system-map-pill--hot {
  background: color-mix(in oklch, var(--sm-neutral-200) 50%, white);
  border-color: var(--sm-neutral-300);
  color: var(--sm-muted);
}

.system-map-pill--idle {
  background: var(--sm-card);
  border-color: var(--sm-neutral-300);
  color: var(--sm-muted);
}

.system-map-hub {
  position: absolute;
  left: 495px;
  top: 322px;
  width: 170px;
  text-align: center;
  pointer-events: none;
}

.system-map-hub__title {
  font-size: 0.9375rem;
  font-weight: 700;
  line-height: 1.35;
  color: #fafaf9;
}

.system-map-hub__pct {
  margin-top: 6px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  color: rgba(250, 250, 249, 0.72);
}

/* Detail + milestones panels */
.system-map-split {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 1024px) {
  .system-map-split {
    grid-template-columns: 1fr;
  }
}

.system-map-panel--detail {
  overflow: hidden;
}

.system-map-panel__bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 22px;
  background: var(--sm-sunken);
  border-bottom: 1px solid var(--sm-border-subtle);
}

.system-map-panel__bar-title {
  flex: 1;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sm-muted);
}

.system-map-badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
}

.system-map-badge--built {
  background: var(--sm-green-100);
  color: var(--sm-green);
}

.system-map-badge--partial {
  background: var(--sm-accent-soft);
  color: var(--sm-accent);
}

.system-map-badge--idle {
  background: var(--sm-neutral-100);
  color: var(--sm-muted);
}

.system-map-panel__body {
  padding: 22px;
}

.system-map-detail-title {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--sm-heading);
}

.system-map-detail-body {
  margin-top: 10px;
  font-size: 0.9375rem;
  line-height: 1.55;
  color: var(--sm-body);
  text-wrap: pretty;
}

.system-map-section-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 13px;
  border: 1px solid var(--sm-border-subtle);
  border-radius: 8px;
}

.system-map-section-row--written {
  background: var(--sm-card);
}

.system-map-section-row--pending {
  background: var(--sm-sunken);
}

.system-map-milestone-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 20px;
  min-width: 0;
  box-sizing: border-box;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.system-map-milestone-row:hover,
.system-map-milestone-row--hover {
  background: color-mix(in oklch, var(--sm-neutral-200) 55%, white);
}

@media (prefers-reduced-motion: reduce) {
  .system-map-block {
    animation: none;
  }

  .system-map-stage__svg circle,
  .system-map-stage__svg line {
    transition: none;
  }
}

.system-map-milestone-title--hot {
  color: var(--sm-heading);
}

.system-map-milestone-title--idle {
  color: var(--sm-muted);
}

.system-map-milestone-code {
  flex: 0 0 auto;
  min-width: 30px;
  height: 19px;
  padding: 0 6px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
}

.system-map-milestones {
  padding: 8px 0 10px;
  max-height: 420px;
  overflow-x: hidden;
  overflow-y: auto;
}

.system-map-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}

@media (max-width: 1024px) {
  .system-map-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 520px) {
  .system-map-stats-grid {
    grid-template-columns: 1fr;
  }
}
