/* ============================================================
   Synaptyx — Page layouts (built on tokens + sx-* primitives)
   ============================================================
   Per-view layout for Dashboard / Archive / Trends / Vault /
   Workflows / Health / Audit. Loads after shell-clean.css.
   Namespace: `pg-`.
   ============================================================ */

/* Generic scrollable page body (everything except the console two-col) */
.app-page { overflow-y: auto; background: var(--bg-canvas); }
.app-page__inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-6) var(--space-8);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

/* Page header: serif-accented display title + supporting meta + actions */
.pg-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; }
.pg-head__titles { display: flex; flex-direction: column; gap: var(--space-2); }
.pg-title {
  font-family: var(--font-display);
  font-size: var(--fz-h1);
  line-height: var(--lh-heading);
  letter-spacing: var(--tr-display);
  font-weight: var(--fw-medium);
  color: var(--fg-primary);
  margin: 0;
}
.pg-title em { font-family: var(--font-serif); font-style: italic; font-weight: var(--fw-regular); color: var(--accent); }
.pg-sub { font-size: var(--fz-meta); color: var(--fg-muted); }
.pg-head__actions { display: flex; align-items: center; gap: var(--space-2); }

.pg-section-label {
  display: flex; align-items: center; gap: var(--space-3);
  margin-top: var(--space-2);
}
.pg-section-label::after { content: ""; flex: 1; height: 1px; background: var(--border-subtle); }

/* ─── Legacy company-module header shim (Phase 3 reskin) ─────────
   The module-mounted /fleet/company/* pages render their headers with
   .co-page-head / .co-page-actions / .page-heading instead of the portal
   .pg-head set. Alias the legacy classes to the same layout + type so the
   whole portal reads consistently without touching every module's JS. */
.co-page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-5); }
.co-page-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.page-heading {
  font-family: var(--font-display);
  font-size: var(--fz-h1);
  line-height: var(--lh-heading);
  letter-spacing: var(--tr-display);
  font-weight: var(--fw-medium);
  color: var(--fg-primary);
  margin: 0;
}
.page-heading em { font-family: var(--font-serif); font-style: italic; font-weight: var(--fw-regular); color: var(--accent); }

/* ─── KPI ROW ────────────────────────────────────────────────── */
.pg-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); }
.pg-kpi { padding: var(--space-4) var(--space-5); position: relative; overflow: hidden; }
.pg-kpi .sx-stat__value { font-size: 2rem; }
.pg-kpi__spark { position: absolute; right: var(--space-4); bottom: var(--space-4); width: 88px; height: 32px; opacity: 0.9; }
.pg-kpi__foot { margin-top: var(--space-3); display: flex; align-items: center; gap: var(--space-2); }

/* ─── DASHBOARD ──────────────────────────────────────────────── */
.pg-dash-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: var(--space-5); align-items: start; }
@media (max-width: 1080px) { .pg-dash-grid { grid-template-columns: 1fr; } }

.pg-hosts-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-3); }
.pg-hostcard { padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); cursor: pointer; transition: border-color var(--dur-hover); }
.pg-hostcard:hover { border-color: var(--border-strong); }
.pg-hostcard__top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.pg-hostcard__name { display: flex; align-items: center; gap: var(--space-2); font-family: var(--font-mono); font-size: var(--fz-mono-sm); color: var(--fg-primary); font-weight: var(--fw-medium); }
.pg-hostcard__meta { font-family: var(--font-mono); font-size: 11px; color: var(--fg-muted); }
.pg-hostcard__metrics { display: flex; flex-direction: column; gap: var(--space-2); margin-top: var(--space-1); }
.pg-metric { display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: var(--space-2); }
.pg-metric__label { font-family: var(--font-mono); font-size: 10px; letter-spacing: var(--tr-meta-upper); text-transform: uppercase; color: var(--fg-muted); }
.pg-metric__val { font-family: var(--font-mono); font-size: 11px; color: var(--fg-secondary); font-variant-numeric: tabular-nums; }

/* Activity feed */
.pg-feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.pg-feed__item { display: grid; grid-template-columns: auto 1fr auto; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border-subtle); align-items: start; }
.pg-feed__item:last-child { border-bottom: 0; }
.pg-feed__icon { width: 26px; height: 26px; border-radius: var(--radius-2); display: inline-flex; align-items: center; justify-content: center; background: var(--bg-surface-2); color: var(--fg-secondary); }
.pg-feed__icon svg { width: 14px; height: 14px; }
.pg-feed__body { min-width: 0; }
.pg-feed__text { font-size: var(--fz-meta); color: var(--fg-secondary); }
.pg-feed__text b { color: var(--fg-primary); font-weight: var(--fw-medium); }
.pg-feed__text code { font-family: var(--font-mono); font-size: 12px; color: var(--accent); }
.pg-feed__time { font-family: var(--font-mono); font-size: 11px; color: var(--fg-muted); white-space: nowrap; }

/* ─── TABLE PAGE (archive / audit) ───────────────────────────── */
.pg-filters { display: flex; align-items: flex-end; gap: var(--space-3); flex-wrap: wrap; padding: var(--space-4); }
.pg-filters .sx-field { gap: var(--space-1); }
.pg-filters .sx-input, .pg-filters .sx-select { height: 32px; }
.pg-filters__spacer { flex: 1; }
.pg-tablewrap { overflow-x: auto; }
.pg-tablewrap .sx-table td { font-family: var(--font-mono); font-size: var(--fz-mono-sm); }
.pg-tablewrap .sx-table td.pg-cell-text { font-family: var(--font-body); }
.pg-pager { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) var(--space-4); }
.pg-rowlink { cursor: pointer; }

/* ─── TRENDS ─────────────────────────────────────────────────── */
.pg-chart-card { padding: var(--space-5); }
.pg-chart-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.pg-chart { width: 100%; height: 300px; display: block; }
.pg-legend { display: flex; flex-wrap: wrap; gap: var(--space-4); margin-top: var(--space-4); padding-top: var(--space-4); border-top: 1px solid var(--border-subtle); }
.pg-legend__item { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--fz-meta); color: var(--fg-secondary); }
.pg-legend__swatch { width: 10px; height: 10px; border-radius: 2px; }
.pg-trends-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: var(--space-5); align-items: start; }
@media (max-width: 1080px) { .pg-trends-grid { grid-template-columns: 1fr; } }

/* chart series palette — coral accent + harmonised oklch hues */
:root {
  --series-1: var(--accent);
  --series-2: var(--info);
  --series-3: oklch(0.72 0.11 150);
  --series-4: oklch(0.74 0.12 90);
  --series-5: oklch(0.66 0.13 300);
}

/* ─── VAULT ──────────────────────────────────────────────────── */
.pg-vault { display: grid; grid-template-columns: 300px 1fr; gap: 0; height: 100%; min-height: 0; }
.pg-vault__tree { border-right: 1px solid var(--border-subtle); display: flex; flex-direction: column; min-height: 0; }
.pg-vault__search { padding: var(--space-3); border-bottom: 1px solid var(--border-subtle); }
.pg-tree { list-style: none; margin: 0; padding: var(--space-2); overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 1px; }
.pg-tree__node { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); border-radius: var(--radius-2); cursor: pointer; font-size: var(--fz-meta); color: var(--fg-secondary); }
.pg-tree__node:hover { background: var(--bg-surface-2); }
.pg-tree__node[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.pg-tree__node svg { width: 14px; height: 14px; flex-shrink: 0; color: var(--fg-muted); }
.pg-tree__node[aria-selected="true"] svg { color: var(--accent); }
.pg-tree__node--child { padding-left: var(--space-6); }
.pg-tree__node--folder { color: var(--fg-primary); font-weight: var(--fw-medium); }
.pg-vault__doc { display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }
.pg-doc { max-width: 760px; margin: 0 auto; padding: var(--space-6); width: 100%; }
.pg-doc h1 { font-family: var(--font-display); font-size: var(--fz-h2); color: var(--fg-primary); margin: 0 0 var(--space-2); }
.pg-doc h2 { font-size: var(--fz-h3); color: var(--fg-primary); margin: var(--space-5) 0 var(--space-2); }
.pg-doc p { font-size: var(--fz-body); line-height: var(--lh-body); color: var(--fg-secondary); margin: 0 0 var(--space-3); }
.pg-doc code { font-family: var(--font-mono); font-size: 13px; background: var(--bg-surface-2); padding: 1px 5px; border-radius: var(--radius-1); color: var(--accent); }
.pg-doc ul { margin: 0 0 var(--space-3); padding-left: var(--space-5); color: var(--fg-secondary); font-size: var(--fz-body); line-height: var(--lh-body); }
.pg-doc__meta { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-5); padding-bottom: var(--space-4); border-bottom: 1px solid var(--border-subtle); }
.pg-secret-row { display: grid; grid-template-columns: 1fr auto auto; gap: var(--space-3); align-items: center; padding: var(--space-3) 0; border-bottom: 1px solid var(--border-subtle); }
.pg-secret-key { font-family: var(--font-mono); font-size: var(--fz-mono-sm); color: var(--fg-primary); }
.pg-secret-val { font-family: var(--font-mono); font-size: var(--fz-mono-sm); color: var(--fg-muted); letter-spacing: 2px; }

/* ─── WORKFLOWS ──────────────────────────────────────────────── */
.pg-wf-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
@media (max-width: 1080px) { .pg-wf-grid { grid-template-columns: repeat(2, 1fr); } }
.pg-wfcard { padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); cursor: pointer; transition: border-color var(--dur-hover); }
.pg-wfcard:hover { border-color: var(--border-strong); }
.pg-wfcard__name { font-size: var(--fz-body); font-weight: var(--fw-medium); color: var(--fg-primary); }
.pg-wfcard__desc { font-size: var(--fz-meta); color: var(--fg-muted); line-height: var(--lh-body); }
.pg-wfcard__foot { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); margin-top: auto; padding-top: var(--space-2); }

/* Workflow editor canvas */
.pg-wf-editor { display: grid; grid-template-columns: 1fr 300px; gap: 0; height: 100%; min-height: 0; }
.pg-wf-canvas {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 1px 1px, var(--border-subtle) 1px, transparent 0);
  background-size: 22px 22px;
  background-color: var(--bg-canvas);
}
.pg-wf-node {
  position: absolute;
  width: 168px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-3);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.pg-wf-node[data-active="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow-2); }
.pg-wf-node__head { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border-subtle); }
.pg-wf-node__head svg { width: 14px; height: 14px; color: var(--accent); }
.pg-wf-node__kind { font-family: var(--font-mono); font-size: 11px; color: var(--fg-primary); font-weight: var(--fw-medium); }
.pg-wf-node__body { padding: var(--space-2) var(--space-3); font-size: 11px; color: var(--fg-muted); }
.pg-wf-edges { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.pg-wf-edges path { stroke: var(--border-strong); stroke-width: 1.5; fill: none; }
.pg-wf-inspector { border-left: 1px solid var(--border-subtle); padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-4); overflow-y: auto; }
.pg-wf-palette { display: flex; flex-wrap: wrap; gap: var(--space-2); }

/* ─── HEALTH ─────────────────────────────────────────────────── */
.pg-health-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
@media (max-width: 1080px) { .pg-health-grid { grid-template-columns: repeat(2, 1fr); } }
.pg-health-card { padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); }
.pg-health-card__top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.pg-health-card__name { display: flex; align-items: center; gap: var(--space-2); font-size: var(--fz-body); font-weight: var(--fw-medium); color: var(--fg-primary); }
.pg-health-card__name svg { width: 16px; height: 16px; color: var(--fg-muted); }
.pg-health-stats { display: flex; flex-direction: column; gap: var(--space-2); }
.pg-health-stat { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); font-size: var(--fz-meta); }
.pg-health-stat__k { color: var(--fg-muted); font-family: var(--font-mono); font-size: 11px; }
.pg-health-stat__v { color: var(--fg-secondary); font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* status text colors */
.pg-ok { color: var(--success); }
.pg-warn { color: var(--warning); }
.pg-err { color: var(--danger); }

/* small inline meta cluster used in several heads */
.pg-metaline { display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap; }
.pg-metaline__item { display: inline-flex; align-items: center; gap: var(--space-2); }
.pg-metaline__k { font-family: var(--font-mono); font-size: 10px; letter-spacing: var(--tr-meta-upper); text-transform: uppercase; color: var(--fg-muted); }
.pg-metaline__v { font-family: var(--font-mono); font-size: var(--fz-meta); color: var(--fg-secondary); }

/* ───────────────────────── /fleet/notes (vt-1164 Phase 5, R3-B9) ───────── */
.sx-page { padding: var(--space-5); max-width: 1280px; margin: 0 auto; }
.sx-page__head { display: flex; flex-direction: column; gap: var(--space-3); margin-bottom: var(--space-4); }
.sx-page__head h1 { font-size: var(--fz-h2, 18px); color: var(--fg-primary); margin: 0; }
.sx-toolbar { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.sx-toolbar [data-notes-search] { flex: 1 1 240px; min-width: 200px; }
.sx-notes__grid { display: grid; grid-template-columns: minmax(260px, 1fr) 2fr; gap: var(--space-4); align-items: start; }
@media (max-width: 900px) { .sx-notes__grid { grid-template-columns: 1fr; } }
.sx-notes__list, .sx-notes__detail { min-width: 0; }
.sx-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.sx-list-item { padding: var(--space-3); border: 1px solid var(--border-default, var(--border, #2a2a2a)); border-radius: var(--radius-md, 6px); background: var(--bg-secondary, transparent); cursor: pointer; transition: border-color .12s ease; }
.sx-list-item:hover { border-color: var(--accent, var(--fg-muted)); }
.sx-list-item__main strong { color: var(--fg-primary); font-size: var(--fz-body); }
.sx-snippet { margin: var(--space-1) 0 0; color: var(--fg-muted); font-size: var(--fz-meta); overflow-wrap: anywhere; }
.sx-card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.sx-card__head h2 { margin: 0; font-size: var(--fz-h3, 15px); color: var(--fg-primary); overflow-wrap: anywhere; }
.sx-actions { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }
.sx-note-body { color: var(--fg-secondary); font-size: var(--fz-body); line-height: 1.55; overflow-wrap: anywhere; }
.sx-note-body h3 { color: var(--fg-primary); margin: var(--space-3) 0 var(--space-2); font-size: var(--fz-body); }
.sx-note-body code { font-family: var(--font-mono); font-size: 0.92em; background: var(--bg-tertiary, rgba(128,128,128,.12)); padding: 0 4px; border-radius: 3px; }
