/* PEM Build restyle: brand tokens, app shell (top bar + single sidebar) and shared components.
   Source of truth for the values: brand/BRAND.md and brand/tokens.css.
   Layout: B shell (dark top bar, light sidebar with expanding sections, grey canvas, white cards)
   with C pages (record pages with details / main / related columns, lists with saved views). */
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@500;600&family=Nunito+Sans:opsz,wght@6..12,400;6..12,600;6..12,700;6..12,800&display=swap");

:root {
  --pem-sky: #00A1F2;
  --pem-blue: #0574CD;
  --pem-blue-dark: #045BA3;
  --pem-blue-tint: #E3F0FB;
  --pem-lime: #98F005;
  --pem-pine: #08345C;          /* Deep blue: top bar, titles (was Pine green) */
  --pem-pine-2: #0E4475;
  --pem-pine-dark: #13263A;
  --pem-ink: #040404;
  --pem-white: #FFFFFF;
  --pem-gray-50: #F5F7F9;
  --pem-gray-75: #EEF3F8;
  --pem-gray-100: #E3E8EE;
  --pem-gray-300: #C9D2DB;
  --pem-gray-500: #8693A0;
  --pem-gray-700: #56636F;
  --pem-success: #18703F;
  --pem-success-bg: #E3F3EA;
  --pem-warning: #995200;
  --pem-warning-bg: #FDF0DC;
  --pem-danger: #C0362C;
  --pem-danger-bg: #FBE7E5;

  --pem-text: var(--pem-pine-dark);
  --pem-text-muted: var(--pem-gray-700);
  --pem-bg: var(--pem-gray-50);
  --pem-surface: var(--pem-white);
  --pem-border: var(--pem-gray-100);
  --pem-border-input: var(--pem-gray-300);

  --pem-font-display: "Poppins", "Avenir Next", "Helvetica Neue", Arial, sans-serif;
  --pem-font-body: "Nunito Sans", "Avenir Next", Avenir, "Helvetica Neue", Arial, sans-serif;
  --pem-radius-control: 6px;
  --pem-radius-card: 10px;
  --pem-shadow-card: 0 1px 2px rgba(8, 52, 92, .08), 0 0 0 1px rgba(8, 52, 92, .06);
  --pem-shadow-pop: 0 12px 32px rgba(8, 52, 92, .18), 0 0 0 1px rgba(8, 52, 92, .08);

  --pem-top-h: 52px;
  --pem-side-w: 236px;
}

/* ---------- Base ---------- */
html { scroll-padding-top: calc(var(--pem-top-h) + 16px); }
body.pem-shell {
  margin: 0;
  padding-top: var(--pem-top-h);
  padding-left: var(--pem-side-w);
  background: var(--pem-bg);
  color: var(--pem-text);
  font-family: var(--pem-font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body.pem-shell :focus-visible { outline: 2px solid var(--pem-blue); outline-offset: 2px; }
.pem-num, .pem-table td.num, .pem-table th.num { font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- Top bar ---------- */
.pem-top {
  position: fixed; inset: 0 0 auto 0; height: var(--pem-top-h); z-index: 1000;
  background: var(--pem-pine); color: #fff;
  display: grid; grid-template-columns: var(--pem-side-w) minmax(0, 1fr) auto; align-items: center;
  font-family: var(--pem-font-body);
}
.pem-top a { color: inherit; text-decoration: none; }
.pem-brand { display: flex; align-items: center; gap: 10px; padding: 0 18px; font-weight: 800; font-size: 15px; letter-spacing: .01em; }
.pem-brand img { height: 28px; width: auto; }
.pem-brand small { font-weight: 600; opacity: .7; font-size: 12px; margin-left: 2px; }
.pem-ham { display: none; background: none; border: 0; color: #fff; padding: 0 14px; height: var(--pem-top-h); cursor: pointer; }
.pem-search { position: relative; justify-self: center; width: min(520px, 100%); }
.pem-search input {
  width: 100%; height: 34px; border-radius: 8px; border: 1px solid transparent; background: var(--pem-pine-2);
  color: #fff; padding: 0 64px 0 36px; font: 600 14px var(--pem-font-body); box-sizing: border-box;
}
.pem-search input::placeholder { color: #A9BED3; font-weight: 400; }
.pem-search input:focus { outline: none; border-color: var(--pem-sky); background: #0B3D6B; }
.pem-search svg { position: absolute; left: 11px; top: 9px; width: 16px; height: 16px; color: #A9BED3; }
.pem-search kbd { position: absolute; right: 10px; top: 8px; font: 600 11px var(--pem-font-body); color: #A9BED3; border: 1px solid #2F5B85; border-radius: 4px; padding: 0 5px; }
.pem-results {
  display: none; position: absolute; top: 40px; left: 0; right: 0; background: #fff; color: var(--pem-text);
  border-radius: 10px; box-shadow: var(--pem-shadow-pop); padding: 6px; max-height: 60vh; overflow: auto;
}
.pem-results.open { display: block; }
.pem-results a { display: flex; flex-direction: column; padding: 8px 10px; border-radius: 7px; color: var(--pem-text); }
.pem-results a small { color: var(--pem-text-muted); font-size: 12px; }
.pem-results a.sel, .pem-results a:hover { background: var(--pem-blue-tint); }
.pem-results .none { padding: 10px; color: var(--pem-text-muted); font-size: 14px; }
.pem-tools { display: flex; align-items: center; gap: 14px; padding: 0 16px; }
.pem-sync { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #CFDCE9; white-space: nowrap; }
.pem-sync i { width: 8px; height: 8px; border-radius: 50%; background: #9fb3b5; display: inline-block; }
.pem-viewer { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #CFDCE9; }
.pem-viewer select {
  height: 32px; border-radius: 7px; border: 1px solid #2F5B85; background: var(--pem-pine-2); color: #fff;
  font: 700 13px var(--pem-font-body); padding: 0 8px; cursor: pointer;
}
.pem-demo { height: 32px; border-radius: 7px; border: 1px solid #2F5B85; background: transparent; color: #fff; font: 700 13px var(--pem-font-body); padding: 0 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.pem-demo:hover { background: var(--pem-pine-2); }
.pem-me { width: 32px; height: 32px; border-radius: 50%; background: var(--pem-lime); color: var(--pem-pine); font: 800 12px var(--pem-font-body); display: grid; place-items: center; flex: none; }

/* ---------- Sidebar ---------- */
.pem-side {
  position: fixed; top: var(--pem-top-h); bottom: 0; left: 0; width: var(--pem-side-w); z-index: 900;
  background: var(--pem-gray-75); border-right: 1px solid var(--pem-gray-100);
  display: flex; flex-direction: column; padding: 12px 10px; box-sizing: border-box; overflow-y: auto;
  font-family: var(--pem-font-body);
}
.pem-side a { text-decoration: none; }
.pem-sec { display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 10px; border-radius: 8px; color: #1C3247; font-weight: 700; font-size: 14px; }
.pem-sec svg { width: 18px; height: 18px; flex: none; color: var(--pem-gray-700); }
.pem-sec:hover { background: rgba(255, 255, 255, .7); }
/* Selected state: a section with pages opens a tree (bold parent, guide line, one highlighted page).
   A section without pages (Jobs) gets the highlight itself. */
.pem-sec.on { background: #fff; color: var(--pem-pine); box-shadow: 0 1px 2px rgba(8, 52, 92, .12); }
.pem-sec.on.open { background: transparent; box-shadow: none; }
.pem-sec.on svg { color: var(--pem-blue); }
.pem-sec .ct { margin-left: auto; background: var(--pem-blue); color: #fff; font-size: 11px; font-weight: 800; border-radius: 9px; padding: 0 7px; line-height: 18px; }
.pem-subs { position: relative; display: flex; flex-direction: column; gap: 1px; margin: 2px 0 10px; }
.pem-subs::before { content: ""; position: absolute; left: 19px; top: 2px; bottom: 2px; width: 1px; background: var(--pem-gray-300); }
.pem-sub { display: flex; align-items: center; height: 31px; margin-left: 28px; padding: 0 10px; border-radius: 7px; font-size: 13.5px; color: var(--pem-gray-700); font-weight: 600; }
.pem-sub:hover { color: var(--pem-pine); background: rgba(255, 255, 255, .6); }
.pem-sub.on { color: var(--pem-pine); font-weight: 800; background: #fff; box-shadow: 0 1px 2px rgba(8, 52, 92, .12); }
.pem-sub .ext { margin-left: 6px; font-size: 11px; opacity: .7; }
.pem-side .grow { flex: 1; min-height: 16px; }
.pem-side .foot { font-size: 11.5px; color: var(--pem-gray-500); padding: 10px 10px 2px; line-height: 1.4; }
.pem-scrim { display: none; }

/* Hide the old floating prototype badge; its sync status moves into the top bar. */
body.pem-shell .pem-proto { display: none !important; }

/* ---------- Page scaffolding ---------- */
.pem-content { padding: 22px 32px 56px; display: flex; flex-direction: column; gap: 16px; min-width: 0; box-sizing: border-box; }
.pem-crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; color: var(--pem-text-muted); }
.pem-crumbs a { color: var(--pem-blue); text-decoration: none; font-weight: 600; }
.pem-crumbs a:hover { text-decoration: underline; }
.pem-crumbs .sep { color: var(--pem-gray-500); }
.pem-ph { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.pem-ph .ttl { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.pem-ph h1, .pem-h1 { font-family: var(--pem-font-display); font-weight: 600; font-size: 24px; line-height: 1.2; color: var(--pem-pine); margin: 0; letter-spacing: -.005em; text-wrap: balance; }
.pem-ph .meta { font-size: 14px; color: var(--pem-text-muted); }
.pem-ph .acts { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pem-h2 { font-family: var(--pem-font-display); font-weight: 600; font-size: 17px; color: var(--pem-pine); margin: 0; }
.pem-eyebrow { font-size: 11.5px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--pem-gray-700); }

/* ---------- Buttons, pills, chips ---------- */
.pem-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: var(--pem-radius-control); border: 1px solid var(--pem-border-input); background: #fff; color: var(--pem-text);
  font: 700 14px var(--pem-font-body); cursor: pointer; text-decoration: none; white-space: nowrap; box-sizing: border-box;
}
.pem-btn:hover { background: var(--pem-gray-50); }
.pem-btn.pri { background: var(--pem-blue); border-color: var(--pem-blue); color: #fff; }
.pem-btn.pri:hover { background: var(--pem-blue-dark); border-color: var(--pem-blue-dark); }
.pem-btn.dark { background: var(--pem-pine); border-color: var(--pem-pine); color: #fff; }
.pem-btn.ghost { border-color: transparent; background: transparent; color: var(--pem-blue); }
.pem-btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.pem-btn[disabled], .pem-btn.is-disabled { opacity: .45; cursor: not-allowed; }
.pem-pill { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 800; white-space: nowrap; background: var(--pem-gray-100); color: var(--pem-gray-700); }
.pem-pill.ok { background: var(--pem-success-bg); color: var(--pem-success); }
.pem-pill.warn { background: var(--pem-warning-bg); color: var(--pem-warning); }
.pem-pill.bad { background: var(--pem-danger-bg); color: var(--pem-danger); }
.pem-pill.info { background: var(--pem-blue-tint); color: var(--pem-blue-dark); }
.pem-pill.dark { background: var(--pem-pine); color: #fff; }
.pem-pill.lime { background: var(--pem-lime); color: var(--pem-pine); }
.pem-chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border: 1px solid var(--pem-border-input); border-radius: 7px; background: #fff; color: var(--pem-text); font: 700 12.5px var(--pem-font-body); cursor: pointer; }
.pem-chip.set, .pem-chip[aria-pressed="true"] { background: var(--pem-blue-tint); border-color: #B7D5F0; color: var(--pem-blue-dark); }
.pem-over { color: var(--pem-danger); }
.pem-under { color: var(--pem-success); }
.pem-muted { color: var(--pem-text-muted); }

/* ---------- Cards and banners ---------- */
.pem-card { background: var(--pem-surface); border-radius: var(--pem-radius-card); box-shadow: var(--pem-shadow-card); min-width: 0; }
.pem-card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px 8px; }
.pem-card-h h2, .pem-card-h h3 { font-family: var(--pem-font-display); font-weight: 600; font-size: 15.5px; color: var(--pem-pine); margin: 0; }
.pem-card-b { padding: 6px 18px 16px; }
.pem-card > .pem-table { border-top: 1px solid var(--pem-border); }
.pem-banner { display: flex; gap: 12px; align-items: flex-start; border-radius: var(--pem-radius-card); padding: 12px 16px; font-size: 14px; background: var(--pem-blue-tint); border: 1px solid #B7D5F0; }
.pem-banner.warn { background: #FFF6E6; border-color: #F2CF94; }
.pem-banner.bad { background: var(--pem-danger-bg); border-color: #F0B9B3; }
.pem-banner.ok { background: var(--pem-success-bg); border-color: #A9D8BD; }
.pem-banner b { display: block; }
.pem-banner .acts { margin-left: auto; display: flex; gap: 8px; align-self: center; }

/* ---------- Layout grids ---------- */
.pem-cols { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.pem-cols > * { min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.pem-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
/* C record page: details | main | related */
.pem-rec { display: grid; grid-template-columns: 250px minmax(0, 1fr) 290px; gap: 16px; align-items: start; }
.pem-rec > * { min-width: 0; }
.pem-props { display: flex; flex-direction: column; }
.pem-prop { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--pem-border); font-size: 13.5px; }
.pem-prop:last-child { border-bottom: 0; }
.pem-prop span { color: var(--pem-text-muted); }
.pem-prop b { font-weight: 700; overflow-wrap: anywhere; }

/* ---------- Stage path (C) ---------- */
.pem-path { display: flex; gap: 3px; overflow-x: auto; }
.pem-path > * {
  flex: 1 0 auto; min-width: 104px; height: 34px; padding: 0 18px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--pem-gray-100); color: var(--pem-gray-700); font: 800 12.5px var(--pem-font-body); border: 0; cursor: pointer; text-decoration: none; white-space: nowrap;
  clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 50%, calc(100% - 12px) 100%, 0 100%, 12px 50%);
}
.pem-path > *:first-child { clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 50%, calc(100% - 12px) 100%, 0 100%); border-radius: 7px 0 0 7px; }
.pem-path > *.done { background: #D6E7F7; color: var(--pem-blue-dark); }
.pem-path > *.on { background: var(--pem-blue); color: #fff; }
.pem-path > *.view { box-shadow: inset 0 -3px 0 var(--pem-pine); }

/* ---------- Tabs and saved views ---------- */
.pem-tabs { display: flex; gap: 22px; border-bottom: 1px solid var(--pem-border); overflow-x: auto; }
.pem-tabs > * { padding: 11px 0 9px; color: var(--pem-gray-700); font: 700 14px var(--pem-font-body); border: 0; border-bottom: 3px solid transparent; background: none; cursor: pointer; white-space: nowrap; text-decoration: none; }
.pem-tabs > *.on, .pem-tabs > *[aria-selected="true"] { color: var(--pem-pine); border-bottom-color: var(--pem-blue); }
.pem-tabs small { color: var(--pem-gray-500); margin-left: 4px; font-weight: 700; }
.pem-views { display: flex; align-items: center; gap: 4px; padding: 10px 12px; flex-wrap: wrap; }
.pem-views > button, .pem-views > a { padding: 6px 11px; border-radius: 7px; font: 700 13px var(--pem-font-body); color: var(--pem-gray-700); background: none; border: 0; cursor: pointer; text-decoration: none; }
.pem-views > .on { background: var(--pem-gray-100); color: var(--pem-pine); }
.pem-views .tools { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.pem-toolbar { display: flex; align-items: center; gap: 6px; padding: 10px 16px; border-top: 1px solid var(--pem-border); flex-wrap: wrap; }
.pem-toolbar input[type="search"], .pem-input {
  height: 32px; border: 1px solid var(--pem-border-input); border-radius: var(--pem-radius-control); padding: 0 10px; font: 600 13.5px var(--pem-font-body); color: var(--pem-text); background: #fff; box-sizing: border-box;
}

/* ---------- Tables (dense, C style) ---------- */
.pem-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.pem-table th, .pem-table td { padding: 9px 14px; border-bottom: 1px solid var(--pem-border); text-align: left; vertical-align: middle; }
.pem-table thead th { font-size: 11.5px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--pem-gray-700); background: #FAFBFD; white-space: nowrap; }
.pem-table tbody tr:hover td { background: #F6F9FC; }
.pem-table tr.click { cursor: pointer; }
.pem-table td .sub { display: block; font-size: 12px; color: var(--pem-text-muted); }
.pem-table td a { color: var(--pem-pine); font-weight: 800; text-decoration: none; }
.pem-table td a:hover { color: var(--pem-blue); text-decoration: underline; }
.pem-table tr.gh td { background: var(--pem-gray-50); font-weight: 800; font-size: 12.5px; color: #1C3247; }
.pem-table tfoot td { font-weight: 800; background: #FAFBFD; border-bottom: 0; }
.pem-scroll { overflow-x: auto; }

/* ---------- Metrics strip (B) ---------- */
.pem-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.pem-metrics > div { padding: 14px 18px; border-left: 1px solid var(--pem-border); font-size: 12.5px; color: var(--pem-text-muted); font-weight: 700; }
.pem-metrics > div:first-child { border-left: 0; }
.pem-metrics b { display: block; font-family: var(--pem-font-display); font-weight: 600; font-size: 22px; color: var(--pem-pine); margin-top: 2px; font-variant-numeric: tabular-nums; }
.pem-metrics small { display: block; font-weight: 600; font-size: 12px; margin-top: 2px; }

/* ---------- Lists, feed, avatars ---------- */
.pem-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--pem-pine); color: #fff; font: 800 11.5px var(--pem-font-body); display: inline-grid; place-items: center; flex: none; overflow: hidden; }
.pem-avatar img { width: 100%; height: 100%; object-fit: cover; }
.pem-list { display: flex; flex-direction: column; }
.pem-li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--pem-border); font-size: 14px; }
.pem-li:last-child { border-bottom: 0; }
.pem-li .grow { flex: 1; min-width: 0; }
.pem-li small { display: block; color: var(--pem-text-muted); font-size: 12.5px; }
.pem-kv { display: grid; grid-template-columns: 1fr auto; row-gap: 8px; column-gap: 12px; font-size: 14px; }
.pem-kv span { color: var(--pem-text-muted); }
.pem-kv b { text-align: right; font-variant-numeric: tabular-nums; }
.pem-empty { padding: 28px; text-align: center; color: var(--pem-text-muted); font-size: 14px; }
.pem-bar { height: 6px; border-radius: 3px; background: var(--pem-gray-100); overflow: hidden; }
.pem-bar > i { display: block; height: 100%; background: var(--pem-blue); border-radius: 3px; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .pem-rec { grid-template-columns: 230px minmax(0, 1fr); }
  .pem-rec > :nth-child(3) { grid-column: 1 / -1; }
  .pem-cols { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  body.pem-shell { padding-left: 0; }
  .pem-top { grid-template-columns: auto minmax(0, 1fr) auto; }
  .pem-ham { display: block; }
  .pem-brand small, .pem-sync span, .pem-viewer label, .pem-demo span { display: none; }
  .pem-side { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--pem-shadow-pop); }
  body.pem-nav-open .pem-side { transform: none; }
  body.pem-nav-open .pem-scrim { display: block; position: fixed; inset: var(--pem-top-h) 0 0 0; background: rgba(8, 52, 92, .35); z-index: 800; }
  .pem-content { padding: 16px 16px 48px; }
  .pem-rec { grid-template-columns: minmax(0, 1fr); }
  .pem-search kbd { display: none; }
}
@media (max-width: 600px) {
  .pem-brand { padding: 0 6px; }
  .pem-brand b { display: none; }
  .pem-tools { gap: 8px; padding: 0 10px; }
  .pem-sync { display: none; }
}
@media (prefers-reduced-motion: reduce) { .pem-side { transition: none; } }
@media print { .pem-top, .pem-side { display: none !important; } body.pem-shell { padding: 0; } }

/* Phones: keep the top bar inside the screen. */
@media (max-width: 600px) {
  .pem-top { grid-template-columns: auto minmax(0, 1fr) auto; }
  .pem-search input { padding-right: 10px; }
  .pem-viewer select { max-width: 104px; }
  .pem-demo { padding: 0 8px; }
  .pem-me { display: none; }
}
@media (max-width: 420px) {
  .pem-demo { display: none; }
  .pem-viewer select { max-width: 92px; }
}
.pem-ham svg { width: 22px; height: 22px; display: block; }
.pem-demo svg { width: 14px; height: 14px; }
/* Laptops: give search room in the top bar. */
@media (max-width: 1240px) and (min-width: 901px) {
  .pem-viewer label, .pem-sync span { display: none; }
  .pem-viewer select { max-width: 150px; }
  .pem-tools { gap: 10px; }
}
