/**
 * PH Operational Modernization Platform — Layout System
 *
 * Structure and positioning only. Colors, typography, and component
 * aesthetics live in design-system.css.
 *
 * Breakpoints:
 *   Desktop  — 1024px+   sidebar persistent 240px
 *   Tablet   — 768-1023  sidebar collapsed 56px (icons)
 *   Mobile   — <768      sidebar hidden, hamburger overlay
 *
 * Layout tokens consumed from design-system.css / app.css:
 *   --phmod-sidebar-width:     240px
 *   --phmod-sidebar-collapsed: 56px
 *   --phmod-topbar-height:     56px
 *   --phmod-space-*            spacing scale
 *   --phmod-radius             border-radius
 *   --phmod-transition         default transition timing
 */

/* ═══════════════════════════════════════════════════════════════════
   0. LAYOUT CUSTOM PROPERTIES (local to this file)
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --phmod-sidebar-width: 240px;
  --phmod-sidebar-collapsed: 56px;
  --phmod-topbar-height: 56px;
  --phmod-content-max-width: 1200px;
  --phmod-content-padding: 1.5rem;
  --phmod-sidebar-transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --phmod-page-transition: 0.2s ease;
}


/* ═══════════════════════════════════════════════════════════════════
   1. PAGE SHELL — .phmod-shell
   ═══════════════════════════════════════════════════════════════════ */

.phmod-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

/* --- Topbar --- */

.phmod-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--phmod-topbar-height);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  flex-shrink: 0;
}

.phmod-topbar__left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.phmod-topbar__logo {
  max-width: 160px;
  height: auto;
  max-height: 36px;
  flex-shrink: 0;
}

.phmod-topbar__right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.phmod-topbar__hamburger {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
}

/* --- Sidebar --- */

.phmod-sidebar {
  position: fixed;
  top: var(--phmod-topbar-height);
  left: 0;
  bottom: 0;
  width: var(--phmod-sidebar-width);
  z-index: 900;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  transition: width var(--phmod-sidebar-transition),
              transform var(--phmod-sidebar-transition);
  display: flex;
  flex-direction: column;
}

.phmod-sidebar__nav {
  flex: 1 1 auto;
  padding: 0.5rem 0;
  overflow-y: auto;
}

.phmod-sidebar__group {
  padding: 0.25rem 0;
}

.phmod-sidebar__group-label {
  padding: 0.5rem 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.phmod-sidebar__item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  min-height: 40px;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  transition: background var(--phmod-page-transition);
}

.phmod-sidebar__item-icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.phmod-sidebar__item-label {
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity var(--phmod-sidebar-transition);
}

.phmod-sidebar__footer {
  flex-shrink: 0;
  padding: 0.75rem 1rem;
}

/* --- Main content area --- */

.phmod-main {
  flex: 1 1 auto;
  margin-top: var(--phmod-topbar-height);
  margin-left: var(--phmod-sidebar-width);
  min-height: calc(100vh - var(--phmod-topbar-height));
  min-height: calc(100dvh - var(--phmod-topbar-height));
  overflow-y: auto;
  transition: margin-left var(--phmod-sidebar-transition);
  position: relative;
}

/* --- Mobile sidebar overlay backdrop --- */

.phmod-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 899;
}


/* ═══════════════════════════════════════════════════════════════════
   2. CONTENT LAYOUTS — page wrappers and page headers
   ═══════════════════════════════════════════════════════════════════ */

/* Standard page wrapper — centered, max 1200px */
.phmod-page {
  max-width: var(--phmod-content-max-width);
  margin: 0 auto;
  padding: var(--phmod-content-padding);
  width: 100%;
  box-sizing: border-box;
}

/* Wide page variant — full width (pipeline Kanban, dashboards) */
.phmod-page--wide {
  max-width: none;
}

/* Page header — title + action buttons row */
.phmod-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
  min-height: 2.5rem;
}

.phmod-page-header__title {
  margin: 0;
  min-width: 0;
  flex: 1 1 auto;
}

.phmod-page-header__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  flex-wrap: wrap;
}

/* ─── Two-column layout — 60/40 split ─── */
/* Used for: program detail, decision detail */

.phmod-two-column {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 1.5rem;
  align-items: start;
}

/* ─── Split panel — 40/60 split ─── */
/* Used for: scoring interface (evidence panel / scoring panel) */

.phmod-split-panel {
  display: grid;
  grid-template-columns: 2fr 3fr;
  gap: 1.5rem;
  align-items: start;
}

/* ─── Sidebar-content layout — fixed sidebar + fluid content ─── */
/* Used for: evaluation form stepper layout */

.phmod-sidebar-content {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 1.5rem;
  align-items: start;
}

.phmod-sidebar-content__aside {
  position: sticky;
  top: calc(var(--phmod-topbar-height) + var(--phmod-content-padding));
}


/* ═══════════════════════════════════════════════════════════════════
   3. GRID SYSTEMS
   ═══════════════════════════════════════════════════════════════════ */

.phmod-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
}

.phmod-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
}

.phmod-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.5rem;
}

/* Auto-fill grid — metric cards, program cards */
.phmod-grid-auto {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.5rem;
}


/* ═══════════════════════════════════════════════════════════════════
   4. FILTER BAR
   ═══════════════════════════════════════════════════════════════════ */

.phmod-filter-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.75rem 0;
  margin-bottom: 1rem;
}

.phmod-filter-bar__group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.phmod-filter-bar__spacer {
  flex: 1 1 auto;
}


/* ═══════════════════════════════════════════════════════════════════
   5. RESPONSIVE TABLES
   ═══════════════════════════════════════════════════════════════════ */

.phmod-table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.phmod-table-wrap table {
  width: 100%;
  min-width: 600px;
  border-collapse: collapse;
}

/* Sticky first column for wide tables */
.phmod-table-wrap--sticky-col table th:first-child,
.phmod-table-wrap--sticky-col table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
}

.phmod-table-wrap table th,
.phmod-table-wrap table td {
  padding: 0.625rem 0.75rem;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

.phmod-table-wrap table td.phmod-table-cell--wrap {
  white-space: normal;
  min-width: 200px;
}


/* ═══════════════════════════════════════════════════════════════════
   6. PIPELINE BOARD LAYOUT
   ═══════════════════════════════════════════════════════════════════ */

.phmod-pipeline-board {
  display: grid;
  grid-template-columns: repeat(8, minmax(200px, 1fr));
  gap: 0.75rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0.5rem; /* room for scrollbar */
}

.phmod-pipeline-column {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 200px;
}

.phmod-pipeline-column__header {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 0.5rem 0.75rem;
  flex-shrink: 0;
}

.phmod-pipeline-column__cards {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow-y: auto;
}


/* ═══════════════════════════════════════════════════════════════════
   7. MOBILE SIDEBAR OVERLAY
   ═══════════════════════════════════════════════════════════════════ */

/* Controlled via .phmod-shell--sidebar-open on mobile */

/* Body scroll lock when sidebar overlay is visible */
.phmod-shell--sidebar-open {
  overflow: hidden;
}

/* Overlay sidebar positioning handled in the mobile breakpoint below */


/* ═══════════════════════════════════════════════════════════════════
   8. EVALUATION FORM LAYOUT
   ═══════════════════════════════════════════════════════════════════ */

.phmod-eval-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 1.5rem;
  align-items: start;
}

.phmod-eval-layout__stepper {
  position: sticky;
  top: calc(var(--phmod-topbar-height) + var(--phmod-content-padding));
}

.phmod-eval-layout__content {
  min-width: 0; /* prevent grid blowout */
}

/* Stepper nav — vertical list of steps */
.phmod-stepper {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.phmod-stepper__item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  text-decoration: none;
  min-height: 40px;
}

.phmod-stepper__number {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Horizontal stepper (for collapsed eval layout on smaller screens) */
.phmod-stepper--horizontal {
  flex-direction: row;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  gap: 0;
  padding-bottom: 0.25rem;
}

.phmod-stepper--horizontal .phmod-stepper__item {
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.5rem 0.75rem;
  flex-shrink: 0;
  text-align: center;
}


/* ═══════════════════════════════════════════════════════════════════
   9. PAGE TRANSITIONS
   ═══════════════════════════════════════════════════════════════════ */

.phmod-content-enter {
  opacity: 0;
  transform: translateY(4px);
}

.phmod-content-enter-active {
  opacity: 1;
  transform: translateY(0);
  transition: opacity var(--phmod-page-transition),
              transform var(--phmod-page-transition);
}

.phmod-content-exit {
  opacity: 1;
  transform: translateY(0);
}

.phmod-content-exit-active {
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity var(--phmod-page-transition),
              transform var(--phmod-page-transition);
}

/* Loading skeleton placeholder */
.phmod-loading-shell {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem 0;
}


/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE — TABLET (768px – 1023px)
   Sidebar collapsed to 56px icon strip
   ═══════════════════════════════════════════════════════════════════ */

@media (max-width: 1023px) and (min-width: 768px) {

  .phmod-sidebar {
    width: var(--phmod-sidebar-collapsed);
  }

  .phmod-sidebar__item-label,
  .phmod-sidebar__group-label,
  .phmod-sidebar__footer {
    opacity: 0;
    pointer-events: none;
    position: absolute;
    width: 0;
    overflow: hidden;
  }

  .phmod-sidebar__item {
    justify-content: center;
    padding: 0.5rem;
  }

  .phmod-main {
    margin-left: var(--phmod-sidebar-collapsed);
  }

  /* Expand sidebar on hover (tablet) */
  .phmod-sidebar:hover,
  .phmod-sidebar:focus-within {
    width: var(--phmod-sidebar-width);
    z-index: 950;
  }

  .phmod-sidebar:hover .phmod-sidebar__item-label,
  .phmod-sidebar:hover .phmod-sidebar__group-label,
  .phmod-sidebar:hover .phmod-sidebar__footer,
  .phmod-sidebar:focus-within .phmod-sidebar__item-label,
  .phmod-sidebar:focus-within .phmod-sidebar__group-label,
  .phmod-sidebar:focus-within .phmod-sidebar__footer {
    opacity: 1;
    pointer-events: auto;
    position: static;
    width: auto;
    overflow: visible;
  }

  .phmod-sidebar:hover .phmod-sidebar__item,
  .phmod-sidebar:focus-within .phmod-sidebar__item {
    justify-content: flex-start;
    padding: 0.5rem 1rem;
  }

  /* Two-column layouts collapse to single column */
  .phmod-two-column,
  .phmod-split-panel {
    grid-template-columns: 1fr;
  }

  /* Grids reduce columns */
  .phmod-grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .phmod-grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }
}


/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE (<768px)
   Sidebar hidden, hamburger overlay
   ═══════════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {

  :root {
    --phmod-content-padding: 1rem;
  }

  /* Show hamburger button */
  .phmod-topbar__hamburger {
    display: flex;
  }

  /* Sidebar off-canvas by default */
  .phmod-sidebar {
    transform: translateX(-100%);
    width: var(--phmod-sidebar-width);
    z-index: 950;
  }

  /* Sidebar visible when shell has open class */
  .phmod-shell--sidebar-open .phmod-sidebar {
    transform: translateX(0);
  }

  /* Show backdrop when sidebar open */
  .phmod-shell--sidebar-open .phmod-sidebar-backdrop {
    display: block;
  }

  /* Main content fills full width */
  .phmod-main {
    margin-left: 0;
  }

  /* Page header stacks on very narrow screens */
  .phmod-page-header {
    flex-direction: column;
    align-items: stretch;
  }

  .phmod-page-header__actions {
    justify-content: flex-start;
  }

  /* All multi-column layouts go single-column */
  .phmod-two-column,
  .phmod-split-panel,
  .phmod-sidebar-content {
    grid-template-columns: 1fr;
  }

  .phmod-sidebar-content__aside {
    position: static;
  }

  /* Grids collapse */
  .phmod-grid-2,
  .phmod-grid-3,
  .phmod-grid-4 {
    grid-template-columns: 1fr;
  }

  .phmod-grid-auto {
    grid-template-columns: 1fr;
  }

  /* Filter bar stacks vertically */
  .phmod-filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .phmod-filter-bar__group {
    width: 100%;
  }

  .phmod-filter-bar__spacer {
    display: none;
  }

  /* Pipeline board — list view on mobile */
  .phmod-pipeline-board {
    grid-template-columns: 1fr;
    overflow-x: visible;
  }

  .phmod-pipeline-column {
    min-height: auto;
  }

  /* Evaluation layout — single column, horizontal stepper */
  .phmod-eval-layout {
    grid-template-columns: 1fr;
  }

  .phmod-eval-layout__stepper {
    position: static;
  }

  .phmod-eval-layout .phmod-stepper {
    flex-direction: row;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0;
    padding-bottom: 0.25rem;
  }

  .phmod-eval-layout .phmod-stepper .phmod-stepper__item {
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
    flex-shrink: 0;
    text-align: center;
  }

  /* Table minimum widths still force scroll */
  .phmod-table-wrap table {
    min-width: 500px;
  }
}


/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE — Evaluation layout breakpoint at 860px
   Stepper collapses to horizontal before full mobile
   ═══════════════════════════════════════════════════════════════════ */

@media (max-width: 860px) and (min-width: 768px) {
  .phmod-eval-layout {
    grid-template-columns: 1fr;
  }

  .phmod-eval-layout__stepper {
    position: static;
  }

  .phmod-eval-layout .phmod-stepper {
    flex-direction: row;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0;
  }

  .phmod-eval-layout .phmod-stepper .phmod-stepper__item {
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
    flex-shrink: 0;
    text-align: center;
  }
}


/* ═══════════════════════════════════════════════════════════════════
   10. PRINT STYLES
   ═══════════════════════════════════════════════════════════════════ */

@media print {

  /* Hide chrome */
  .phmod-topbar,
  .phmod-sidebar,
  .phmod-sidebar-backdrop,
  .phmod-topbar__hamburger,
  .phmod-filter-bar,
  .phmod-page-header__actions {
    display: none !important;
  }

  /* Reset main to full width */
  .phmod-main {
    margin-left: 0 !important;
    margin-top: 0 !important;
    overflow: visible !important;
  }

  .phmod-shell {
    overflow: visible !important;
    display: block !important;
  }

  /* Full-width content */
  .phmod-page {
    max-width: none;
    padding: 0;
    margin: 0;
  }

  /* Multi-column layouts go single-column for clean print */
  .phmod-two-column,
  .phmod-split-panel,
  .phmod-sidebar-content,
  .phmod-eval-layout {
    display: block;
  }

  .phmod-two-column > *,
  .phmod-split-panel > *,
  .phmod-sidebar-content > *,
  .phmod-eval-layout > * {
    margin-bottom: 1rem;
  }

  /* Grids print as single column */
  .phmod-grid-2,
  .phmod-grid-3,
  .phmod-grid-4,
  .phmod-grid-auto {
    display: block;
  }

  .phmod-grid-2 > *,
  .phmod-grid-3 > *,
  .phmod-grid-4 > *,
  .phmod-grid-auto > * {
    margin-bottom: 0.75rem;
  }

  /* Pipeline board prints as stacked list */
  .phmod-pipeline-board {
    display: block;
  }

  .phmod-pipeline-column {
    page-break-inside: avoid;
    margin-bottom: 1rem;
  }

  /* Tables print without scroll wrapper constraints */
  .phmod-table-wrap {
    overflow: visible;
  }

  .phmod-table-wrap table {
    min-width: 0;
  }

  .phmod-table-wrap table th,
  .phmod-table-wrap table td {
    white-space: normal;
  }

  /* Avoid page breaks inside cards and table rows */
  .phmod-card,
  .phmod-table-wrap table tr {
    page-break-inside: avoid;
  }

  /* Page title for print header */
  .phmod-page-header__title {
    page-break-after: avoid;
  }

  /* Hide stepper in print — content is what matters */
  .phmod-eval-layout__stepper {
    display: none !important;
  }

  /* Ensure links show URLs in print */
  .phmod-page a[href^="http"]::after {
    content: " (" attr(href) ")";
    word-break: break-all;
  }
}


/* ═══════════════════════════════════════════════════════════════════
   UTILITY — Layout helpers
   ═══════════════════════════════════════════════════════════════════ */

/* Visually hidden but accessible to screen readers */
.phmod-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Flex row with common gap */
.phmod-flex-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Flex column */
.phmod-flex-col {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Stack — vertical spacing between children */
.phmod-stack > * + * {
  margin-top: 1rem;
}

.phmod-stack--sm > * + * {
  margin-top: 0.5rem;
}

.phmod-stack--lg > * + * {
  margin-top: 1.5rem;
}

/* Cluster — horizontal wrapping with gap */
.phmod-cluster {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* Sticky container — sticks below topbar */
.phmod-sticky {
  position: sticky;
  top: calc(var(--phmod-topbar-height) + var(--phmod-content-padding));
  z-index: 10;
}

/* Full-bleed — break out of .phmod-page max-width */
.phmod-full-bleed {
  width: 100vw;
  position: relative;
  left: 50%;
  right: 50%;
  margin-left: -50vw;
  margin-right: -50vw;
}

/* Truncate single-line text */
.phmod-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Aspect ratio box (for chart containers, etc.) */
.phmod-aspect-16-9 {
  aspect-ratio: 16 / 9;
}

.phmod-aspect-4-3 {
  aspect-ratio: 4 / 3;
}

.phmod-aspect-1-1 {
  aspect-ratio: 1 / 1;
}
