/* 테크트리 화면. 학년이 가로, 영역이 세로 */

.tree-layout { margin-top: 16px; }

@media (min-width: 1200px) {
  body.has-detail .main { padding-right: calc(var(--spacing-page) + 340px); }
}

/* ---------- 판 ---------- */

.tree {
  position: relative;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
  overflow: auto;
  max-height: calc(100vh - var(--topbar-height) - 110px);
}

.tree__grid {
  position: relative;
  display: grid;
  grid-template-columns: 92px repeat(var(--tree-cols, 12), 320px);   /* 열 수는 데이터의 학년 수 */
  min-width: max-content;
}

/* 머리글 두 줄: 위는 학교급(열 병합, 가운데 정렬), 아래는 학년 */

.tree__corner, .tree__stage, .tree__gradehead {
  position: sticky;
  z-index: 3;
  background: var(--color-surface-subtle);
}

.tree__corner { top: 0; left: 0; z-index: 5; }
.tree__corner--low { top: 32px; border-bottom: 1px solid var(--color-border); }

.tree__stage {
  top: 0;
  height: 32px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--color-divider);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--color-text-strong);
}

/* 학교급마다 바탕 명도를 한 단계씩 달리해 묶어 보이게 한다 */
.tree__stage[data-stage="초"], .tree__gradehead[data-stage="초"] { background: #f7f7f7; }
.tree__stage[data-stage="중"], .tree__gradehead[data-stage="중"] { background: #f0f0f0; }
.tree__stage[data-stage="고"], .tree__gradehead[data-stage="고"] { background: #e6e6e6; }
.tree__cell[data-stage="중"] { background: #fdfdfd; }
.tree__cell[data-stage="고"] { background: #f8f8f8; }

/* 학교급이 바뀌는 열은 띠부터 맨 아래까지 같은 색 한 줄로 긋는다 */
.tree__stage { border-left: 1px solid var(--color-border-strong); }
.tree__gradehead.is-stage-start, .tree__cell.is-stage-start { border-left-color: var(--color-border-strong); }

.tree__gradehead {
  top: 32px;
  padding: 6px 12px 8px;
  border-bottom: 1px solid var(--color-border);
  border-left: 1px solid var(--color-divider);
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--color-text-strong);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
}

.tree__gradehead small {
  display: block;
  margin-top: 1px;
  font-size: 10px;
  font-weight: 500;
  color: var(--color-text-disabled);
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 영역 줄 */

.tree__lane {
  position: sticky;
  left: 0;
  z-index: 2;
  padding: 24px 10px 12px 12px;
  border-top: 1px solid var(--color-divider);
  background: var(--color-surface);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--color-text-strong);
  word-break: keep-all;
}

.tree__cell {
  display: flex;
  flex-flow: row wrap;
  align-content: flex-start;
  align-items: flex-start;
  gap: 6px 8px;
  padding: 24px 12px 14px 14px;   /* 위 여백에 레일이 지나간다 */
  border-top: 1px solid var(--color-divider);
  border-left: 1px solid var(--color-divider);
  min-height: 60px;
}

.tree__sub {
  flex-basis: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-muted);
}

.tree__sub:first-child { margin-top: 0; }

/* ---------- 마디 ---------- */

.node {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 4px 9px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  background: var(--color-surface);
  font: inherit;
  font-size: 12.5px;
  line-height: 1.45;
  word-break: keep-all;
  color: var(--color-text);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast),
    color var(--transition-fast), opacity var(--transition-fast);
}

.node:hover { border-color: var(--color-primary-light); }



.node__key {
  flex: none;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--color-primary);
}

.node.is-selected {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
  font-weight: 600;
}

.node.is-selected .node__key { background: #fff; }

.node.is-up, .node.is-down {
  background: var(--color-primary-soft);
  border-color: var(--color-primary-light);
  color: var(--color-primary-dark);
  font-weight: 500;
}

.tree.has-focus .node:not(.is-selected):not(.is-up):not(.is-down) { opacity: 0.35; }

/* ---------- 간선 ---------- */

.tree__edges {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: visible;
}

.tree__edges path[data-from] {
  fill: none;
  stroke: #cfcfcf;
  stroke-width: 1;
  stroke-linecap: round;
  transition: stroke var(--transition-fast), opacity var(--transition-fast);
}

.tree__edges marker path { fill: #cfcfcf; }
.tree__edges marker#arrow-on path { fill: var(--color-primary); }

.tree.has-focus .tree__edges path[data-from] { opacity: 0.12; }

.tree.has-focus .tree__edges path.is-on {
  stroke: var(--color-primary);
  stroke-width: 1.5;
  opacity: 1;
  marker-end: url(#arrow-on);
}

/* ---------- 오른쪽 상세 ---------- */

.detail {
  position: fixed;
  top: var(--topbar-height);
  right: 0;
  bottom: 0;
  z-index: 30;
  width: 340px;
  max-width: 92vw;
  overflow-y: auto;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform var(--transition-panel);
}

.detail.is-open { transform: none; }

.detail__close { position: absolute; top: 10px; right: 10px; }

.detail__head { padding: 16px 52px 14px 18px; border-bottom: 1px solid var(--color-border); }

.detail__eyebrow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  font-size: 12px;
  color: var(--color-text-muted);
}

.detail__eyebrow i { font-style: normal; margin: 0 6px; color: var(--color-text-disabled); }

.detail__title {
  margin-top: 6px;
  font-size: 17px;
  font-weight: 700;
  color: var(--color-text-strong);
  letter-spacing: -0.01em;
}

.detail__key {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-control);
  background: var(--color-primary-soft);
  font-size: 12px;
  color: var(--color-primary-dark);
}

.detail__key .node__key { margin-top: 6px; }
.detail__key b { font-weight: 600; }

.detail__section { padding: 16px 18px; border-bottom: 1px solid var(--color-divider); }
.detail__section:last-child { border-bottom: none; }

.detail__label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--color-text-disabled);
  margin-bottom: 10px;
}

.unit + .unit { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--color-divider); }
.unit__name { font-size: 13.5px; font-weight: 600; color: var(--color-text-strong); }
.unit__detail { margin-top: 3px; font-size: 13px; color: var(--color-text); line-height: 1.65; }
.unit__codes { display: flex; flex-wrap: wrap; gap: 4px; }

.standards { margin-top: 8px; }
.standard { display: flex; gap: 8px; align-items: baseline; margin-top: 6px; font-size: 12.5px; color: var(--color-text-muted); line-height: 1.6; }

.code {
  flex: none;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--color-neutral-bg);
  font-size: 10.5px;
  color: var(--color-neutral-text);
  font-variant-numeric: tabular-nums;
  cursor: help;
}

.links { display: flex; flex-wrap: wrap; gap: 6px; }

.link-node {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  background: var(--color-surface);
  font: inherit;
  font-size: 12px;
  color: var(--color-text);
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.link-node:hover { border-color: var(--color-primary-light); background: var(--color-primary-soft); }
.link-node small { color: var(--color-text-disabled); font-size: 11px; }

.symptom { font-size: 13px; color: var(--color-text); padding: 5px 0; line-height: 1.5; }
.symptom + .symptom { border-top: 1px solid var(--color-divider); }

/* ---------- 좁은 화면 ---------- */

@media (max-width: 900px) {
  .tree { max-height: none; -webkit-overflow-scrolling: touch; }
  .tree__grid { grid-template-columns: 72px repeat(var(--tree-cols, 12), 280px); }
  .node { padding: 7px 10px; font-size: 13.5px; }
  .tree__gradehead small { font-size: 11.5px; }
  .node { min-height: 40px; }
  .tree__sub { font-size: 12px; }
  .link-node small { font-size: 12px; }
  .symptom { font-size: 14.5px; padding: 8px 0; }

  /* 상세는 화면 전체를 덮는다 (머리 위로 올라와야 제목이 가리지 않는다) */
  .detail {
    top: 0;
    z-index: 75;
    width: 100%;
    max-width: none;
    border-left: none;
    padding-bottom: env(safe-area-inset-bottom);
    overscroll-behavior: contain;
    visibility: hidden;
    transition: transform var(--transition-panel), visibility 0s linear 220ms;
  }
  .detail.is-open { visibility: visible; transition: transform var(--transition-panel); }
  .detail__close { top: 8px; right: 6px; }
  .detail__head { padding: 16px 56px 14px 16px; }
  .detail__eyebrow { font-size: 13px; }
  .detail__title { font-size: 19px; }
  .detail__key { font-size: 13.5px; }
}
