/**
 * @file
 * Base/Generic Styles for ASPR Organization Charts
 *
 * This file contains generic, reusable classes that can be used across
 * different organization chart templates (BC, bio, program, etc.)
 *
 * These classes use CSS custom properties for easy theming.
 */

/* ============================================
   CSS Custom Properties (Theme Variables)
   ============================================ */

:root {
  /* Colors */
  --orgchart-primary-color: #005ea2;
  --orgchart-secondary-color: #97d4ea;
  --orgchart-text-color: #1b1b1b;
  --orgchart-text-light: #ffffff;
  --orgchart-border-color: #dfe1e2;
  --orgchart-bg-light: #f0f0f0;

  /* Connector dimensions */
  --orgchart-connector-width: 1px;
  --orgchart-connector-color: var(--orgchart-secondary-color);
  --orgchart-spine-height: 60px;
  --orgchart-item-connector-height: 30px;
  --orgchart-horizontal-line-height: 2px;

  /* Item dimensions */
  --orgchart-item-width: 220px;
  --orgchart-item-gap: 0.875rem;
  --orgchart-item-header-height: 250px;

  /* Spacing */
  --orgchart-container-padding: 2rem 0;
  --orgchart-max-width: 1650px;
}

/* ============================================
   Container Classes
   ============================================ */

/* Main container - generic version */
.aspr-orgchart {
  position: relative;
  max-width: var(--orgchart-max-width);
  margin: 0 auto;
  padding: var(--orgchart-container-padding);
}

/* Override USWDS prose width constraint */
.usa-prose.aspr-orgchart {
  max-width: var(--orgchart-max-width) !important;
}

/* Override usa-prose spacing for connectors */
.usa-prose .aspr-orgchart__connector-spine {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}

.usa-prose .aspr-orgchart__items {
  margin-top: 0 !important;
}

/* ============================================
   Header/Top Row Layout
   ============================================ */

.aspr-orgchart__header-row {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 0;
  margin-bottom: 0;
  width: 100%;
}

.aspr-orgchart__sidebar--left {
  flex: 0 0 30%;
  display: flex;
  justify-content: flex-end;
  align-items: flex-start;
}

.aspr-orgchart__header-main {
  flex: 0 0 40%;
  display: flex;
  justify-content: center;
  margin-bottom: 0;
}

.aspr-orgchart__sidebar--right {
  flex: 0 0 30%;
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
}

/* ============================================
   Card/Box Styles
   ============================================ */

.aspr-orgchart__card {
  background: #ffffff;
  border: 2px solid var(--orgchart-primary-color);
  border-radius: 0;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.aspr-orgchart__card--header {
  width: 500px;
  height: 300px;
}

.aspr-orgchart__card-icon {
  margin-top: 20px;
  margin-bottom: 1rem;
}

.aspr-orgchart__card-icon img {
  width: 72px;
  height: 72px;
  display: block;
  margin: 0 auto;
}

.aspr-orgchart__card-title {
  font-size: 1.75rem;
  font-weight: 300;
  color: var(--orgchart-text-light);
  line-height: 2.5rem;
  margin: 0;
  padding: 0;
}

.aspr-orgchart__card-text {
  font-size: 1.2em;
  color: var(--orgchart-text-light);
  margin-top: 0.75rem;
}

/* ============================================
   Connector Lines
   ============================================ */

/* Vertical spine from header to items */
.aspr-orgchart__connector-spine {
  height: var(--orgchart-spine-height);
  width: var(--orgchart-connector-width);
  background-color: var(--orgchart-connector-color);
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

/* Items container with horizontal connector line */
.aspr-orgchart__items {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: var(--orgchart-item-width);
  gap: var(--orgchart-item-gap);
  justify-content: center;
  margin-top: 0;
  position: relative;
  padding-top: 0;
}

/* Horizontal connector line across all items */
.aspr-orgchart__items::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: var(--orgchart-horizontal-line-height);
  background-color: var(--orgchart-connector-color);
  z-index: 0;
  /* Margins calculated as: (item-width / 2) - (connector-width / 2) */
  margin-left: calc(var(--orgchart-item-width) / 2 - 4px);
  margin-right: calc(var(--orgchart-item-width) / 2 - 4px);
  margin-top: 0;
  margin-bottom: 0;
  padding: 0;
}

/* ============================================
   Individual Items
   ============================================ */

.aspr-orgchart__item {
  width: var(--orgchart-item-width);
  min-width: var(--orgchart-item-width);
  max-width: var(--orgchart-item-width);
  min-height: var(--orgchart-item-width);
  background-color: transparent;
  border-radius: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: visible;
  margin-top: var(--orgchart-item-connector-height);
}

/* Vertical connector from horizontal line to each item */
.aspr-orgchart__item-connector {
  width: var(--orgchart-connector-width);
  height: var(--orgchart-item-connector-height);
  background-color: var(--orgchart-connector-color);
  margin: 0 auto;
  position: absolute;
  top: calc(var(--orgchart-item-connector-height) * -1);
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
}

/* Item header (icon + title area) */
.aspr-orgchart__item-header {
  width: 100%;
  height: var(--orgchart-item-header-height);
  min-height: var(--orgchart-item-header-height);
  max-height: var(--orgchart-item-header-height);
  background: var(--orgchart-secondary-color);
  border-radius: 0;
  padding: 20px 1rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  flex-shrink: 0;
  overflow: hidden;
}

/* Item icon */
.aspr-orgchart__item-icon {
  margin-top: 20px;
  margin-bottom: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.aspr-orgchart__item-icon img {
  width: 64px;
  height: 64px;
  display: block;
}

/* Item title */
.aspr-orgchart__item-title {
  font-size: 1.0em;
  font-weight: 400;
  color: var(--orgchart-text-color);
  margin: 0;
  padding: 0 0 1.0em 0;
  text-align: center;
  line-height: 1.3;
}

.aspr-orgchart__item-title a {
  color: var(--orgchart-text-color);
  text-decoration: none;
}

.aspr-orgchart__item-title a:hover {
  color: var(--orgchart-primary-color);
  text-decoration: underline;
}

/* Item body/children list */
.aspr-orgchart__item-body {
  list-style: none;
  padding: 0;
  margin: 0;
  width: 100%;
  border-left: 1px solid var(--orgchart-secondary-color);
}

.aspr-orgchart__item-body li {
  padding: 1em 0.5em;
  border-bottom: 1px solid var(--orgchart-secondary-color);
  background-color: #ffffff;
  text-align: left;
  list-style: none;
}

.aspr-orgchart__item-body li:last-child {
  border-radius: 0 0 0.5rem 0.5rem;
}

.aspr-orgchart__item-body li::before {
  display: none;
  content: none;
}

.aspr-orgchart__item-body li a {
  color: var(--orgchart-text-color);
  text-decoration: none;
  font-weight: 500;
  display: block;
  font-size: 0.9375rem;
}

.aspr-orgchart__item-body li a:hover {
  color: var(--orgchart-primary-color);
  text-decoration: underline;
}

/* ============================================
   Sidebar Lists
   ============================================ */

.aspr-orgchart__list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-width: 300px;
  width: 100%;
}

.aspr-orgchart__sidebar--left .aspr-orgchart__list {
  margin-left: auto;
}

.aspr-orgchart__sidebar--right .aspr-orgchart__list {
  margin-right: auto;
}

.aspr-orgchart__list li {
  padding: 0.75rem 1rem;
  background-color: var(--orgchart-bg-light);
  border: 1px solid var(--orgchart-border-color);
  border-radius: 0.25rem;
  margin-bottom: 0.75rem;
}

.aspr-orgchart__sidebar--left .aspr-orgchart__list li {
  background-color: transparent;
  border: 1px solid var(--orgchart-secondary-color);
  border-left: none;
  border-radius: 0;
  margin-right: 1.0em;
  text-align: right;
}

.aspr-orgchart__sidebar--right .aspr-orgchart__list li {
  background-color: transparent;
  border: 1px solid var(--orgchart-secondary-color);
  border-right: none;
  border-radius: 0;
  margin-left: 1.0em;
  text-align: left;
}

.aspr-orgchart__list li p {
  margin: 0;
  font-weight: 400;
  font-size: 1rem;
}

.aspr-orgchart__list li a {
  color: var(--orgchart-primary-color);
  text-decoration: none;
}

.aspr-orgchart__list li a:hover {
  text-decoration: underline;
  color: #1a4480;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 1200px) {
  .aspr-orgchart__header-row {
    flex-direction: column;
    align-items: center;
  }

  .aspr-orgchart__sidebar--left,
  .aspr-orgchart__sidebar--right,
  .aspr-orgchart__header-main {
    flex: 1 1 100%;
    max-width: 500px;
    margin-bottom: 1rem;
  }

  .aspr-orgchart__items {
    grid-auto-flow: row;
    justify-items: center;
  }
}

@media (max-width: 640px) {
  .aspr-orgchart__card--header {
    width: 100%;
    max-width: 500px;
    height: auto;
    min-height: 300px;
  }

  .aspr-orgchart__item {
    width: 100%;
    max-width: 300px;
  }

  .aspr-orgchart__item-header,
  .aspr-orgchart__item-body {
    width: 100%;
  }
}

/* ============================================
   Utility Classes
   ============================================ */

/* Hide element visually but keep accessible */
.aspr-orgchart__sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}
