/* ============================================================
   앱 셸: 왼쪽 사이드바 (220px, 또는 768px 이하에서 56px 아이콘 레일) + 위 막대 (56px) + 스크롤하는 내용.
   접두사 `shell`. 마크업은 templates/layout.html 이다:

     a.skip-link
     div.shell
       aside.shell-sidebar
         div.shell-wordmark
         nav.shell-nav[aria-label]
           div.shell-navGroup > span.shell-navGroupLabel + a.shell-navItem(svg[aria-hidden] + span.shell-navLabel)
         div.shell-sidebarBottom > a.shell-userChip, form.shell-langForm, form.shell-signOutForm
       div.shell-main > header.shell-topBar > h1.shell-pageTitle, main#content.shell-content
   ============================================================ */

.shell {
  display: flex;
  height: 100%;
  width: 100%;
  background: var(--wall-bg);
}

/* ── 건너뛰기 링크: 키보드 포커스를 받을 때까지 숨겨진다 ───────── */

.skip-link {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link:focus {
  position: fixed;
  top: var(--sp2);
  left: var(--sp2);
  z-index: 3000;
  width: auto;
  height: auto;
  min-height: var(--h-ctl);
  margin: 0;
  padding: 0 var(--sp4);
  overflow: visible;
  clip: auto;
  clip-path: none;
  display: inline-flex;
  align-items: center;
  background: var(--accent-btn);
  color: var(--on-accent);
  font-weight: 600;
  text-decoration: none;
}

/* ── 사이드바 ──────────────────────────────────────────────── */

.shell-sidebar {
  width: var(--w-sidebar);
  flex-shrink: 0;
  background: var(--panel-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.shell-sidebarTop {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: var(--sp4) 0;
}

/* 워드마크 */
.shell-wordmark {
  display: block;
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
  padding: 0 var(--sp4) var(--sp4);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp3);
  text-decoration: none;
}

.shell-sidebar > .shell-wordmark {
  padding-top: var(--sp4);
}

.shell-wordmarkImg {
  display: block;
  width: 100%;
  max-width: 148px;
  height: auto;
}

/* 내비게이션 */
.shell-nav {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp2);
  padding: 0 var(--sp2);
  overflow-y: auto;
}

.shell-navGroup {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.shell-navGroup + .shell-navGroup {
  margin-top: var(--sp2);
  padding-top: var(--sp3);
  border-top: 1px solid var(--border);
}

.shell-navGroupLabel {
  padding: var(--sp1) var(--sp3);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-faint);
}

.shell-navItem {
  display: flex;
  align-items: center;
  gap: var(--sp3);
  min-height: var(--h-ctl);
  padding: 0 var(--sp3) 0 calc(var(--sp3) - 3px);
  border-left: 3px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: var(--fs-md);
  font-weight: 500;
  text-decoration: none;
  transition: background 0.1s ease, color 0.1s ease;
}

.shell-navItem svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.shell-navItem:hover {
  background: var(--wall-bg);
  color: var(--text-primary);
  text-decoration: none;
}

/* 현재 페이지: 옅은 색, 왼쪽의 막대, 더 굵은 글. */
.shell-navItem[aria-current="page"],
.shell-navItemActive {
  background: var(--accent-tint);
  color: var(--accent-strong);
  font-weight: 600;
  border-left-color: var(--accent);
}

.shell-navItem[aria-current="page"] svg,
.shell-navItemActive svg {
  color: var(--accent);
}

/* ── 사이드바 아래: 사용자 칩, 언어, 로그아웃 ────────── */

.shell-sidebarBottom {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp2);
  padding: var(--sp3);
  border-top: 1px solid var(--border);
}

/* 칩은 /account 로 링크한다. */
.shell-userChip,
.shell-userInfo {
  display: flex;
  align-items: center;
  gap: var(--sp2);
  flex: 1 1 100%;
  min-width: 0;
}

.shell-userChip {
  min-height: var(--h-ctl);
  padding: var(--sp1) var(--sp2);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  text-decoration: none;
}

.shell-userChip:hover {
  background: var(--wall-bg);
  color: var(--text-primary);
  text-decoration: none;
}

.shell-userAvatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: var(--accent-tint);
  color: var(--accent-strong);
  font-size: var(--fs-xs);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid var(--accent-line);
}

.shell-userMeta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}

.shell-userName {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.shell-userRole {
  font-size: var(--fs-xs);
  color: var(--text-faint);
}

/* 언어 버튼 (한국어 / English): 이어 붙인 쌍, 현재 언어가 눌려 있다. */
.shell-langForm {
  display: flex;
  flex: 1 1 auto;
}

/* 맨 레이아웃 (로그인, 강제 변경, 방문자의 오류) 에는 사이드바가 없다: 쌍은 오른쪽 위에 뜬다. */
.shell-langBar {
  position: fixed;
  top: var(--sp3);
  right: var(--sp3);
  z-index: 10;
}

.shell-langBar .shell-langForm,
.shell-langBar .shell-langBtn {
  flex: none;
}

.shell-langBar .shell-langBtn {
  white-space: nowrap;
  padding: 0 var(--sp3);
}

.shell-langBtn {
  flex: 1 1 0;
  min-width: 44px;
  min-height: var(--h-sm);
  padding: 0 var(--sp2);
  background: var(--surface-raised);
  border: 1px solid var(--field-border);
  color: var(--text-dim);
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1.2;
}

.shell-langBtn + .shell-langBtn {
  margin-left: -1px;
}

.shell-langBtn:hover {
  background: var(--fill-dim);
  color: var(--text-primary);
}

.shell-langBtn[aria-pressed="true"] {
  position: relative;
  z-index: 1;
  background: var(--accent-tint);
  border-color: var(--accent);
  color: var(--accent-strong);
}

.shell-langBtn:focus-visible {
  position: relative;
  z-index: 2;
}

/* 로그아웃 버튼은 양식 안에 산다 (CSRF 가 붙은 POST /logout); 양식 자체가 레이아웃에 영향을 주어서는 안 된다. */
.shell-signOutForm {
  display: flex;
  flex-shrink: 0;
  margin-left: auto;
}

.shell-signOutBtn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp2);
  min-width: var(--h-ctl);
  min-height: var(--h-ctl);
  padding: 0 var(--sp2);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  font-size: var(--fs-sm);
  font-weight: 600;
  flex-shrink: 0;
}

.shell-signOutBtn:hover {
  background: var(--wall-bg);
  color: var(--text-primary);
}

/* ── 주 내용 영역 ────────────────────────────────────── */

.shell-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.shell-topBar {
  height: var(--h-topbar);
  background: var(--chrome-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp3);
  padding: 0 var(--sp6);
  flex-shrink: 0;
}

.shell-pageTitle {
  min-width: 0;
  font-size: var(--fs-lg);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.shell-topBarActions {
  display: flex;
  align-items: center;
  gap: var(--sp2);
}

/* 사용자 계정의 만료 안내: 제목 막대와 페이지 사이, 페이지 자신의 padding 위에. */
.shell-banner {
  flex-shrink: 0;
  padding: var(--sp3) var(--content-pad) 0;
}

/* position: relative 는 이 스크롤 상자를 절대 위치 자손 (.sr-only 글, 눈에 숨긴 파일 입력) 의 containing block 으로
   만들므로, 뷰포트보다 더 아래에 있는 것은 문서를 셸 너머로 늘이는 대신 내용과 함께 스크롤된다. */
.shell-content {
  position: relative;
  flex: 1;
  overflow-y: auto;
  padding: var(--content-pad);
}

/* ── 반응형: 좁은 화면에서 56px 아이콘 레일 ────────
   라벨은 접근성 트리에 남고 (눈에 숨기며, 결코 display:none 이 아니다), 각 링크는 title 도 지니므로, 레일 아이콘이
   이름을 지킨다 (디자이너 #8). */
@media (max-width: 768px) {
  .shell-sidebar {
    width: var(--w-rail);
  }

  .shell-wordmark {
    display: none;
  }

  .shell-navLabel,
  .shell-navGroupLabel,
  .shell-userMeta,
  .shell-signOutBtn > :not(svg) {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }

  .shell-nav {
    padding: 0 var(--sp1);
  }

  .shell-navGroup + .shell-navGroup {
    margin-top: 0;
    padding-top: var(--sp2);
  }

  .shell-navItem {
    justify-content: center;
    padding: 0;
  }

  .shell-sidebarBottom {
    /* 레일에는 칩, 언어 버튼과 로그아웃이 나란히 들어가지 못하므로, 쌓는다 */
    flex-direction: column;
    flex-wrap: nowrap;
    justify-content: center;
    padding: var(--sp3) var(--sp1);
  }

  .shell-userChip,
  .shell-userInfo {
    flex: 0 0 auto;
    justify-content: center;
    padding: 0;
  }

  .shell-userAvatar {
    width: 36px;
    height: 36px;
  }

  .shell-langForm {
    flex: 0 0 auto;
    flex-direction: column;
    /* "English" 에는 자리가 필요하다: 쌍이 레일만큼 넓어서, 그 글자가 테두리에 닿지 않는다. */
    width: calc(var(--w-rail) - var(--sp1));
  }

  .shell-langBtn {
    flex: 0 0 auto;
    min-width: 0;
    width: 100%;
    padding: 0;
    white-space: nowrap;
  }

  .shell-langBtn + .shell-langBtn {
    margin-left: 0;
    margin-top: -1px;
  }

  .shell-signOutForm {
    margin-left: 0;
  }

  /* 맨 페이지 (로그인) 의 쌍에는 맞출 레일이 없다: 행으로 남아, 카드 위에 걸리지 않는다. */
  .shell-langBar .shell-langForm {
    flex-direction: row;
    width: auto;
  }

  .shell-langBar .shell-langBtn {
    width: auto;
    margin-top: 0;
  }

  .shell-langBar .shell-langBtn + .shell-langBtn {
    margin-left: -1px;
  }

  .shell-topBar {
    padding: 0 var(--sp4);
  }

  :root {
    --content-pad: var(--sp4);
  }
}

/* 강제 색상은 배경과 그림자를 버리므로, 현재 페이지에는 자기 테두리가 필요하다. */
@media (forced-colors: active) {
  .shell-navItem[aria-current="page"],
  .shell-navItemActive,
  .shell-langBtn[aria-pressed="true"] {
    outline: 2px solid CanvasText;
    outline-offset: -2px;
  }
}
