/* =================================================================
   PlanHub Subcontractor Onboarding — Data Acquisition Visualizer
   Experimental prototype-only styles. All component classes prefixed
   with .phe- (PlanHub experimental) per ds-manifest.json.
   ================================================================= */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--typography-font-family-base), system-ui, sans-serif;
  font-size: var(--typography-font-size-s);
  color: var(--text-primary);
  background-color: var(--bg-canvas);
  line-height: var(--typography-line-height-m);
}

html, body { height: 100%; }

body.phe-page {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------------------------------------------------------------
   Page shell
   --------------------------------------------------------------- */

/* ---------------------------------------------------------------
   Masthead (dark hero band) — holds the title + the filters
   --------------------------------------------------------------- */

.phe-masthead {
  flex-shrink: 0;
  background-color: var(--bg-app-shell);
  color: var(--text-inverse);
  box-shadow: var(--elevation-light-low);
  z-index: 10;
}

.phe-masthead__inner {
  padding: var(--layout-space-s) var(--layout-space-m);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--layout-space-l);
  flex-wrap: wrap;
}

.phe-masthead__title-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.phe-masthead__eyebrow {
  margin: 0;
  font-size: var(--typography-font-size-xs);
  font-weight: var(--typography-font-weight-semi-bold);
  letter-spacing: var(--typography-letter-spacing-wide);
  text-transform: uppercase;
  color: var(--color-primitives-green-500);
}

.phe-masthead__title {
  margin: 0;
  font-size: var(--typography-font-size-l);
  font-weight: var(--typography-font-weight-semi-bold);
  line-height: var(--typography-line-height-s);
  letter-spacing: var(--typography-letter-spacing-tight);
  color: var(--text-inverse);
}

/* Toggles sit on the dark masthead — give them a dark segmented-control
   look: translucent track, light inactive labels, white active pill. */
.phe-masthead .tabBar {
  background-color: rgba(255, 255, 255, 0.08);
}

.phe-masthead .tabBar__tab {
  color: rgba(255, 255, 255, 0.75);
}

.phe-masthead .tabBar__tab:hover:not(.tabBar__tab--active) {
  background-color: rgba(255, 255, 255, 0.14);
  color: var(--text-inverse);
}

.phe-masthead .tabBar__tab--active {
  background-color: var(--bg-canvas);
  color: var(--action-primary-default);
}

.phe-page__main {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Edge-to-edge tier sidebar on the left, timeline canvas fills the rest */
.phe-split {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: row;
}

/* Left: edge-to-edge tier panel — flush from the dark header to the bottom */
.phe-section--tiers {
  width: 300px;
  flex-shrink: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-canvas);
  border-right: var(--layout-border-default) solid var(--border-default);
  overflow: hidden;
}

.phe-section--tiers .phe-tier-table {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* Right: light-gray canvas holding the white timeline panel */
.phe-section--timeline {
  flex: 1;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: var(--layout-space-s);
  background-color: var(--color-primitives-neutral-100);
  overflow: hidden;
}

.phe-section--timeline .phe-timeline-wrapper {
  flex: 1;
  min-height: 0;
  overflow: auto; /* both axes */
}

/* ---------------------------------------------------------------
   Filter bar
   --------------------------------------------------------------- */

.phe-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--layout-space-l);
  row-gap: var(--layout-space-s);
}

.phe-filters__group {
  display: flex;
  flex-direction: column;
  gap: var(--layout-space-xxs);
}

.phe-filters__label {
  font-size: var(--typography-font-size-xs);
  font-weight: var(--typography-font-weight-semi-bold);
  letter-spacing: var(--typography-letter-spacing-wide);
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.phe-filters__tabbar {
  align-self: flex-start;
}

.phe-filters__legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--layout-space-s);
  align-items: center;
  margin-left: auto;
  padding: var(--layout-space-xs) var(--layout-space-s);
  background-color: var(--bg-surface);
  border-radius: var(--layout-radius-s);
  border: var(--layout-border-default) solid var(--border-subtle);
}

/* ---------------------------------------------------------------
   Method chips (acquisition method indicator)
   --------------------------------------------------------------- */

.phe-method {
  display: inline-flex;
  align-items: center;
  gap: var(--layout-space-xxs);
  font-size: var(--typography-font-size-xs);
  font-weight: var(--typography-font-weight-medium);
  color: var(--text-secondary);
  white-space: nowrap;
}

.phe-method__dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: var(--layout-radius-full);
  flex-shrink: 0;
}

.phe-method--manual .phe-method__dot { background-color: var(--color-primitives-green-500); }
.phe-method--auto .phe-method__dot { background-color: var(--status-ai-border); }

/* Sparkle icon used in the legend for the automatic method */
.phe-method__icon {
  font-size: 15px;
  color: var(--status-ai-border);
  flex-shrink: 0;
}

/* In-table method chip variant */
.phe-method-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 8px;
  border-radius: var(--layout-radius-xs);
  border: none;
  font-size: 12px;
  line-height: 16px;
  font-weight: var(--typography-font-weight-medium);
  letter-spacing: var(--typography-letter-spacing-normal);
  white-space: nowrap;
}

/* Chips on the white sidebar — manual neutral, auto purple */
.phe-method-chip--manual {
  background-color: var(--bg-surface);
  color: var(--text-secondary);
}

.phe-method-chip--auto {
  background-color: var(--status-ai-surface);
  color: var(--status-ai-text);
}

/* On the active green pill, chips go translucent white to stay legible */
.phe-tier-row.is-active .phe-method-chip {
  background-color: rgba(255, 255, 255, 0.22);
  color: var(--text-inverse);
}

/* Method icon inside the left-panel chips (cursor = manual, sparkle = auto) */
.phe-method-chip__icon {
  font-size: 13px;
  color: inherit;
}

/* ---------------------------------------------------------------
   Sections
   --------------------------------------------------------------- */

.phe-section {
  display: flex;
  flex-direction: column;
  gap: var(--layout-space-s);
}

.phe-section__heading {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.phe-section__title {
  margin: 0;
  font-size: var(--typography-font-size-xs);
  font-weight: var(--typography-font-weight-semi-bold);
  letter-spacing: var(--typography-letter-spacing-wide);
  text-transform: uppercase;
  color: var(--action-primary-default);
  line-height: var(--typography-line-height-s);
}

.phe-section__sub {
  margin: 0;
  font-size: 11px;
  color: var(--text-tertiary);
  line-height: 14px;
}

/* ---------------------------------------------------------------
   Tier table
   --------------------------------------------------------------- */

.phe-tier-table {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding-bottom: var(--layout-space-s);
}

.phe-tier-card {
  flex-shrink: 0;
  background-color: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  /* balance the space below the last row with the header's top padding,
     so each group divider sits centered between the two groups */
  padding-bottom: var(--layout-space-s);
}

/* Divider line between tier groups */
.phe-tier-card + .phe-tier-card {
  border-top: var(--layout-border-default) solid var(--border-subtle);
}

/* Section label — muted gray, no bar, no dividers (nav-group heading) */
.phe-tier-card__header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: baseline;
  gap: var(--layout-space-xs);
  padding: var(--layout-space-m) var(--layout-space-s) var(--layout-space-xs);
  background-color: var(--bg-canvas);
}

.phe-tier-card__title {
  margin: 0;
  font-size: var(--typography-font-size-xs);
  font-weight: var(--typography-font-weight-semi-bold);
  text-transform: uppercase;
  letter-spacing: var(--typography-letter-spacing-wide);
  color: var(--text-tertiary);
}

.phe-tier-card__sub {
  margin: 0;
  margin-left: auto;
  font-size: 10px;
  color: var(--text-disabled);
}

.phe-tier-card__body {
  display: flex;
  flex-direction: column;
}

/* Nav-style row — no dividers, rounded hover/active pill, inset from edges */
.phe-tier-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--layout-space-xs);
  padding: 8px 12px;
  margin: 1px var(--layout-space-xs);
  border-radius: var(--layout-radius-m);
  cursor: pointer;
  transition: background-color 0.12s ease;
}

.phe-tier-row:hover {
  background-color: var(--bg-surface-hover);
}

.phe-tier-row.is-active {
  background-color: var(--color-primitives-green-500);
}

.phe-tier-row__cell {
  font-size: 13px;
  color: var(--text-secondary);
}

.phe-tier-row__cell--name {
  flex: 1;
  min-width: 0;
  font-weight: var(--typography-font-weight-medium);
}

.phe-tier-row.is-active .phe-tier-row__cell--name {
  color: var(--text-inverse);
  font-weight: var(--typography-font-weight-semi-bold);
}

.phe-tier-row__cell--method {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  justify-content: flex-end;
  flex-shrink: 0;
}

.phe-tier-row__cell--notes {
  color: var(--text-tertiary);
  font-size: var(--typography-font-size-xs);
}

/* ---------------------------------------------------------------
   Timeline
   --------------------------------------------------------------- */

.phe-timeline-wrapper {
  background-color: var(--bg-canvas);
  border: var(--layout-border-default) solid var(--border-default);
  border-radius: var(--layout-radius-m);
  overflow-x: auto;
  box-shadow: var(--elevation-light-low);
}

.phe-timeline {
  display: grid;
  /* JS sets --step-count. Columns = 1 lane-label + N step columns. With
     12–13 day columns the wrapper will scroll horizontally; each column
     stays readable at ~200px. Rows: header + three content lanes
     (User / System / Comms), each sized to its content. */
  grid-template-columns: 32px repeat(var(--step-count, 7), minmax(200px, 1fr));
  grid-template-rows: auto auto auto;
  min-height: 100%;
  position: relative;
}

/* Step header row (top) — plain icon + label on one line */
.phe-timeline__step-header {
  padding: var(--layout-space-xs);
  border-bottom: var(--layout-border-strong) solid var(--border-default);
  border-right: var(--layout-border-default) solid var(--border-subtle);
  background-color: var(--bg-surface);
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: background-color 0.12s ease;
  position: relative;
  min-width: 0;
}

.phe-timeline__step-header:last-of-type {
  border-right: none;
}

.phe-timeline__step-header:hover {
  background-color: var(--bg-surface-hover);
}

.phe-timeline__step-header.is-active {
  background-color: var(--bg-surface-selected);
}

.phe-timeline__step-header.is-active::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 2px solid var(--action-primary-default);
  border-bottom: none;
  pointer-events: none;
}

/* Plain icon in each event header, accent by event kind (no container) */
.phe-timeline__event-icon {
  font-size: 18px;
  color: var(--action-primary-default);
  flex-shrink: 0;
}

.phe-timeline__event-icon--pre { color: var(--text-tertiary); }
.phe-timeline__event-icon--end { color: var(--status-highlight-border); }

.phe-timeline__step-header--pre { background-color: var(--bg-surface-hover); }
.phe-timeline__step-header--signup { background-color: var(--bg-surface-selected); }
.phe-timeline__step-header--end { background-color: var(--status-highlight-surface); }

.phe-timeline__step-title {
  font-size: var(--typography-font-size-xs);
  font-weight: var(--typography-font-weight-semi-bold);
  color: var(--text-primary);
  line-height: var(--typography-line-height-xxs);
  word-break: break-word;
}

/* Lane label cells (left column) — plain neutral text, no color, no icons */
.phe-timeline__lane-label {
  grid-column: 1;
  padding: var(--layout-space-xs) 2px;
  background-color: var(--bg-surface);
  border-right: var(--layout-border-default) solid var(--border-subtle);
  border-bottom: var(--layout-border-default) solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
}

.phe-timeline__lane-label:last-of-type {
  border-bottom: none;
}

.phe-timeline__lane-label-text {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 10px;
  font-weight: var(--typography-font-weight-semi-bold);
  letter-spacing: var(--typography-letter-spacing-wide);
  text-transform: uppercase;
  color: var(--text-tertiary);
  white-space: nowrap;
}

/* Step cells per lane */
.phe-timeline__cell {
  padding: var(--layout-space-xs);
  border-right: var(--layout-border-default) solid var(--border-subtle);
  border-bottom: var(--layout-border-default) solid var(--border-subtle);
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: var(--layout-space-xxs);
  min-height: 80px;
  min-width: 0;
  position: relative;
  word-break: break-word;
}

.phe-timeline__cell--comms {
  border-bottom: none;
}

/* Neutral lanes — colour lives in the pills, not the cell backgrounds.
   A faint gray on Comms keeps the three bands legible. */
.phe-timeline__cell--user { background-color: transparent; }

.phe-timeline__cell--system { background-color: transparent; }

.phe-timeline__cell--comms {
  background-color: color-mix(in srgb, var(--bg-surface) 45%, transparent);
}

.phe-timeline__cell:last-of-type {
  border-right: none;
}

.phe-timeline__cell.is-active {
  outline: 2px solid var(--action-primary-default);
  outline-offset: -2px;
  z-index: 2;
}

.phe-timeline__cell-empty {
  color: var(--text-disabled);
  font-style: italic;
}

.phe-timeline__cell-text { margin: 0; }

.phe-timeline__cell-text strong {
  color: var(--text-primary);
  font-weight: var(--typography-font-weight-semi-bold);
}

.phe-timeline__cell-value {
  margin-top: 2px;
  padding: 2px var(--layout-space-xxs);
  background-color: var(--bg-canvas);
  border-left: 3px solid var(--action-primary-default);
  border-radius: var(--layout-radius-xs);
  font-size: 11px;
  line-height: 14px;
  color: var(--text-primary);
  font-style: italic;
  word-break: break-word;
}

.phe-timeline__cell-fields {
  display: flex;
  flex-direction: column;
  gap: var(--layout-space-xxs);
  margin-top: var(--layout-space-xxs);
  padding-top: var(--layout-space-xxs);
  border-top: var(--layout-border-default) dashed var(--border-subtle);
}

.phe-timeline__field-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px 4px;
  border-radius: var(--layout-radius-xs);
  transition: background-color 0.12s ease;
}

.phe-timeline__field-row.is-highlight {
  background-color: var(--bg-surface-selected);
}

.phe-timeline__field-pill {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  padding: 2px 8px;
  border-radius: var(--layout-radius-xs);
  font-size: 12px;
  line-height: 16px;
  font-weight: var(--typography-font-weight-semi-bold);
  letter-spacing: var(--typography-letter-spacing-normal);
  border: none;
  color: var(--text-primary);
  white-space: nowrap;
  transition: background-color 0.12s ease, color 0.12s ease;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Subtle tint fill by method — no border. Manual neutral, Auto purple. */
.phe-timeline__field-pill[data-method="manual"] {
  background-color: var(--bg-surface);
  color: var(--text-secondary);
}
.phe-timeline__field-pill[data-method="auto"] {
  background-color: var(--status-ai-surface);
  color: var(--status-ai-text);
}

/* Selected state — must come after the method tints so it wins */
.phe-timeline__field-pill.is-highlight {
  background-color: var(--action-primary-default);
  color: var(--text-inverse);
}

/* Method icon prefix inside pills (cursor = manual, sparkle = auto).
   Inherits the pill's text colour so manual reads green, auto purple. */
.phe-timeline__field-pill-icon {
  font-size: 13px;
  margin-right: 3px;
  color: inherit;
  flex-shrink: 0;
}

/* When an auto pill is highlighted (white-on-green selection), keep the
   sparkle legible against the filled background. */
.phe-timeline__field-pill.is-highlight .phe-timeline__field-pill-icon {
  color: var(--text-inverse);
}

.phe-timeline__field-trigger {
  display: block;
  font-size: 11px;
  line-height: 14px;
  color: var(--text-tertiary);
  font-style: italic;
  word-break: break-word;
}

/* ---------------------------------------------------------------
   Motion — a single quick fade when a panel re-renders
   --------------------------------------------------------------- */

@keyframes pheFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.phe-fade {
  animation: pheFade 150ms ease;
}

/* ---------------------------------------------------------------
   Note panel
   --------------------------------------------------------------- */

.phe-section--note .panel {
  background-color: var(--bg-canvas);
}

.phe-note__text {
  margin: 0;
  font-size: var(--typography-font-size-s);
  color: var(--text-secondary);
  line-height: var(--typography-line-height-m);
}

.phe-note__text--muted {
  color: var(--text-tertiary);
  font-size: var(--typography-font-size-xs);
}

/* ---------------------------------------------------------------
   DS component minimal styles needed inline
   (full DS styles aren't in tokens.css — these are the html-patterns
   styles for the components used: TabBar, Panel)
   --------------------------------------------------------------- */

.tabBar {
  display: inline-flex;
  align-items: center;
  background-color: var(--bg-surface);
  border-radius: var(--layout-radius-s);
  padding: var(--layout-space-xxs);
  gap: var(--layout-space-xxs);
}

.tabBar__tab {
  appearance: none;
  background: transparent;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--layout-space-xxs);
  padding: var(--layout-space-xxs) var(--layout-space-s);
  border-radius: var(--layout-radius-xs);
  font-family: var(--typography-font-family-base);
  font-size: var(--typography-font-size-s);
  font-weight: var(--typography-font-weight-medium);
  color: var(--text-secondary);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.tabBar__tab:hover:not(.tabBar__tab--active) {
  background-color: var(--bg-surface-hover);
  color: var(--text-primary);
}

.tabBar__tab:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--focus-ring);
}

.tabBar__tab--active {
  background-color: var(--bg-canvas);
  color: var(--action-primary-default);
  box-shadow: var(--elevation-light-low);
}

.tabBar--m .tabBar__tab { height: 32px; }
.tabBar--s .tabBar__tab { height: 28px; font-size: var(--typography-font-size-xs); }

.panel {
  background-color: var(--bg-canvas);
  border: var(--layout-border-default) solid var(--border-subtle);
  border-radius: var(--layout-radius-m);
  overflow: hidden;
}

.panel__header {
  display: flex;
  align-items: center;
  gap: var(--layout-space-s);
  padding: var(--layout-space-s) var(--layout-space-m);
}

.panel__header--border-default {
  border-bottom: var(--layout-border-default) solid var(--border-subtle);
}

.panel__header-left {
  display: flex;
  flex: 1;
  align-items: center;
  gap: var(--layout-space-xs);
}

.panel__title {
  margin: 0;
  font-size: var(--typography-font-size-m);
  font-weight: var(--typography-font-weight-semi-bold);
  color: var(--text-primary);
}

.panel__body {
  display: flex;
  flex-direction: column;
}

.panel__body--padding-standard {
  padding: var(--layout-space-m);
}

.panel__body--gap-standard {
  gap: var(--layout-space-s);
}

/* ---------------------------------------------------------------
   Responsive
   --------------------------------------------------------------- */

@media (max-width: 900px) {
  .phe-page__header-inner,
  .phe-page__main {
    padding-left: var(--layout-space-s);
    padding-right: var(--layout-space-s);
  }

  .phe-tier-card__body {
    grid-template-columns: 1fr;
  }

  .phe-tier-card__head-cell {
    display: none;
  }

  .phe-tier-row__cell {
    padding: var(--layout-space-xs) var(--layout-space-s);
  }

  .phe-tier-row__cell--name {
    padding-top: var(--layout-space-s);
    border-bottom: none;
    background-color: var(--bg-surface-hover);
  }
}
