/* ============================================================
   PROBLEM DOCTOR & BOTTLENECK PREDICTOR
   Stage-wise risk + cause/solution explorer for 650 BOQ items.
   ============================================================ */

.section-eyebrow {
  display: inline-block;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-orange-light);
  margin-bottom: var(--space-xs);
}

/* ---------- Toolbar ---------- */
.pd-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.pd-toolbar .form-input {
  flex: 1 1 320px;
  max-width: 520px;
}

.pd-stat {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  font-weight: var(--font-weight-medium);
}

/* ---------- Layout ---------- */
.pd-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: var(--space-lg);
  align-items: start;
}

/* ---------- List panel ---------- */
.pd-list-panel {
  position: sticky;
  top: 84px;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-md);
  max-height: calc(100vh - 110px);
  display: flex;
  flex-direction: column;
}

.pd-list-title {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-navy);
  margin-bottom: var(--space-sm);
}

.pd-count {
  color: var(--color-text-light);
  font-weight: var(--font-weight-normal);
}

.pd-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.pd-list::-webkit-scrollbar { width: 8px; }
.pd-list::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 8px; }

.pd-item {
  width: 100%;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-sm) var(--space-sm);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.pd-item:hover {
  background: var(--color-bg);
}

.pd-item--active {
  background: linear-gradient(135deg, var(--color-navy), var(--color-navy-light));
  border-color: var(--color-navy);
}

.pd-item--active .pd-item__name { color: #fff; }
.pd-item--active .pd-item__id { color: rgba(255, 255, 255, 0.7); }

.pd-item__name {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  line-height: 1.3;
}

.pd-item__id {
  font-size: var(--font-size-xs);
  color: var(--color-text-light);
  font-variant-numeric: tabular-nums;
}

.pd-list__empty,
.pd-list__more {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  padding: var(--space-md) var(--space-sm);
  text-align: center;
}
.pd-list__more { font-size: var(--font-size-xs); }

/* ---------- Detail panel ---------- */
.pd-detail {
  min-height: 420px;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-xl);
}

.pd-empty {
  text-align: center;
  padding: var(--space-3xl) var(--space-lg);
  color: var(--color-text-muted);
}

.pd-empty__icon {
  color: var(--color-orange);
  opacity: 0.5;
  margin-bottom: var(--space-md);
}

.pd-empty__title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--color-navy);
  margin-bottom: var(--space-xs);
}

.pd-empty__sub { font-size: var(--font-size-sm); max-width: 420px; margin: 0 auto; }

.pd-loading {
  padding: var(--space-2xl);
  text-align: center;
  color: var(--color-text-muted);
}
.pd-loading--err { color: var(--color-danger); }

/* ---------- Detail header ---------- */
.pd-detail__head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-md);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-lg);
}

.pd-detail__id {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  color: var(--color-orange);
  letter-spacing: 0.05em;
}

.pd-detail__name {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-navy);
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.pd-detail__counts { display: flex; gap: var(--space-sm); flex-wrap: wrap; }

.pd-pill {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.12);
  color: #b45309;
  white-space: nowrap;
}
.pd-pill--alt { background: rgba(59, 130, 246, 0.12); color: #1d4ed8; }

/* ---------- Stage chips ---------- */
.pd-stagebar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-bottom: var(--space-lg);
}

.pd-chip {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-white);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.pd-chip:hover { border-color: var(--color-orange); color: var(--color-orange); }

.pd-chip--active {
  background: linear-gradient(135deg, var(--color-navy), var(--color-navy-light));
  border-color: var(--color-navy);
  color: #fff;
}

/* ---------- Sections ---------- */
.pd-section { margin-bottom: var(--space-xl); }

.pd-section__title {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  color: var(--color-navy);
  margin-bottom: var(--space-md);
}

.pd-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.pd-dot--warn { background: var(--color-warning); }
.pd-dot--cure { background: var(--color-green); }

.pd-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-md);
}

/* ---------- Cards ---------- */
.pd-card {
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-warning);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  background: var(--gradient-card);
  transition: box-shadow var(--transition-fast), transform var(--transition-fast);
}

.pd-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.pd-card--problem { border-left-color: var(--color-green); }

.pd-card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.pd-stage {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-light);
}

.pd-badge {
  font-size: 0.65rem;
  font-weight: var(--font-weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.pd-badge--high { background: rgba(239, 68, 68, 0.13); color: #dc2626; }
.pd-badge--med { background: rgba(245, 158, 11, 0.15); color: #b45309; }
.pd-badge--low { background: rgba(34, 197, 94, 0.15); color: #15803d; }
.pd-badge--neutral { background: var(--color-bg-alt); color: var(--color-text-muted); }

.pd-card__title {
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  line-height: 1.3;
  margin-bottom: var(--space-sm);
}

.pd-row { margin-bottom: var(--space-sm); }

.pd-row__k {
  display: block;
  font-size: 0.7rem;
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-light);
  margin-bottom: 2px;
}

.pd-row__v {
  display: block;
  font-size: var(--font-size-sm);
  color: var(--color-text);
  line-height: 1.4;
}

.pd-row__v--accent { color: var(--color-orange-hover); font-weight: var(--font-weight-medium); }
.pd-row__v--solution { color: #15803d; font-weight: var(--font-weight-medium); }

.pd-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-top: var(--space-sm);
  padding-top: var(--space-sm);
  border-top: 1px dashed var(--color-border);
}

.pd-tag {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  background: var(--color-bg);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
}
.pd-tag--owner { background: rgba(0, 31, 63, 0.06); color: var(--color-navy); font-weight: var(--font-weight-medium); }

.pd-none {
  grid-column: 1 / -1;
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  padding: var(--space-md);
  text-align: center;
  background: var(--color-bg);
  border-radius: var(--radius-md);
}

/* ---------- Visual risk profile (charts) ---------- */
.pd-viz {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.pd-viz__card {
  background: var(--gradient-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-md) var(--space-lg);
  box-shadow: var(--shadow-sm);
}
.pd-viz__card--wide { display: flex; flex-direction: column; }
.pd-viz__card--full { grid-column: 1 / -1; }

.pd-viz__title {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-light);
  margin-bottom: var(--space-sm);
}

/* Donut */
.sw-donut {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex-wrap: wrap;
}
.sw-donut__num {
  font-size: 1.4rem;
  font-weight: 800;
  fill: var(--color-navy);
}
.sw-donut__lbl {
  font-size: 0.6rem;
  font-weight: 600;
  fill: var(--color-text-light);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.sw-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sw-legend li {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.sw-legend strong { color: var(--color-text); margin-left: auto; }
.sw-legend__dot { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

/* Horizontal bars */
.sw-hbars { display: flex; flex-direction: column; gap: 6px; }
.sw-hbar {
  display: grid;
  grid-template-columns: 120px 1fr 52px;
  align-items: center;
  gap: var(--space-sm);
}
.sw-hbar__lbl {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sw-hbar__track {
  height: 12px;
  background: var(--color-bg-alt);
  border-radius: 999px;
  overflow: hidden;
}
.sw-hbar__fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  transition: width var(--transition-slow);
}
.sw-hbar__val {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  text-align: right;
}

/* Line chart */
.sw-line__grid { stroke: var(--color-border); stroke-width: 1; }
.sw-line__axis { font-size: 9px; fill: var(--color-text-light); }
.sw-legend--row { flex-direction: row; flex-wrap: wrap; gap: var(--space-md); margin-top: var(--space-sm); }

/* Grouped bars (planned vs actual) */
.sw-gbars { display: flex; flex-direction: column; gap: var(--space-sm); }
.sw-gbars__legend { display: flex; gap: var(--space-md); font-size: var(--font-size-xs); color: var(--color-text-muted); margin-bottom: var(--space-xs); }
.sw-gbars__legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.sw-gbar { display: grid; grid-template-columns: 150px 1fr 42px; align-items: center; gap: var(--space-sm); }
.sw-gbar__lbl { font-size: var(--font-size-xs); color: var(--color-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sw-gbar__st { font-style: normal; font-size: 0.6rem; font-weight: 700; padding: 1px 6px; border-radius: 999px; margin-left: 4px; }
.sw-gbar__st--delayed { background: rgba(239,68,68,.13); color: #dc2626; }
.sw-gbar__st--at-risk { background: rgba(245,158,11,.15); color: #b45309; }
.sw-gbar__st--on-track { background: rgba(34,197,94,.15); color: #15803d; }
.sw-gbar__bars { display: flex; flex-direction: column; gap: 3px; }
.sw-gbar__track { height: 9px; background: var(--color-bg-alt); border-radius: 999px; overflow: hidden; }
.sw-gbar__fill { display: block; height: 100%; border-radius: 999px; transition: width var(--transition-slow); }
.sw-gbar__val { font-size: var(--font-size-xs); font-weight: var(--font-weight-bold); color: var(--color-navy); text-align: right; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .pd-layout { grid-template-columns: 1fr; }
  .pd-list-panel { position: static; max-height: 360px; }
  .pd-detail { padding: var(--space-lg); }
  .pd-viz { grid-template-columns: 1fr; }
  .sw-hbar { grid-template-columns: 90px 1fr 44px; }
  .sw-gbar { grid-template-columns: 110px 1fr 38px; }
}
