/*
 * ss-pages — Studio 셸 배치 (ss = shadcn-studio). 설계 §5.5, §12.
 *
 * 원본 블록(shadcn-studio, MCP로 소스를 읽었다):
 *   application-shell-01·12  전체 높이 사이드바 + 오른쪽 열(헤더·내용)
 *   dashboard-header-05      헤더 오른쪽 묶음(상태·새로고침·계정)
 *   login-page-05            bg-muted 위 가운데 카드
 * JSX의 배치 유틸리티만 옮겼다. 색·모서리·글자는 components.css의 [data-slot] 규칙이 맡는다.
 *
 * 블록과 다른 점:
 *   - 경계는 900px다(블록은 md 768px). 그 아래에서 studio/navigation.js가 탭 목록을 서랍(Sheet)으로 옮긴다.
 *   - 헤더는 sticky가 아니다. 화면 안의 sticky 요소(진단·발송·공지망 상세 top 1rem, 방 관리 구역 막대 top 0)를
 *     가리기 때문이다. 화면을 새로 쓰는 단계에서 다시 정한다.
 *   - 사이드바 접기(icon·offcanvas)와 rail은 옮기지 않는다.
 *
 * 원본 컨트롤러가 쓰는 상태를 그대로 읽는다(테스트가 컨트롤러 소스와 함께 확인한다):
 *   session-expiry.js는 배너의 className을 통째로 바꾼다 → #session-expiry-banner, .is-final
 *   mobile-header.js는 상태 상세를 클래스로 연다 → .is-mobile-expanded
 *   shadcn-studio/dashboard/controller.js는 요약·준비 상태에 .is-ready·.is-unready·.is-failed를 단다
 */
@layer ss-pages {
  /* ── 문서 뿌리: 4단계 철거 때 파일럿 studio-admin.css(html:has(> body.studio-admin)·body.studio-admin)에서 옮겼다 ── */
  /* 화면(뷰포트)이 스크롤을 갖는다. 넘침을 숨긴 조상은 sticky 막대와 body 넘침 잠금을 깨므로 body는 가로만 자른다. */
  html:has(> body.ss-app) { overflow: visible; }
  body.ss-app { overflow-x: clip; overflow-y: visible; }
  /* 901px 이상에서는 스크롤 막대 자리를 늘 둔다. 화면을 바꿔 세로 스크롤이 생기고 없어질 때 내용이 옆으로 흔들리지 않는다. */
  @media (min-width: 901px) { html:has(> body.ss-app) { scrollbar-gutter: stable; } }

  /* ── 로그인 후: 사이드바 | 오른쪽 열 ─────────────────────────────────── */
  .ss-shell-app { display: grid; grid-template-columns: var(--ss-sidebar-width) minmax(0, 1fr); align-items: start; }
  /* 긴 화면에서도 메뉴가 손에 닿는다. 창이 낮으면 메뉴만 따로 스크롤한다. */
  .ss-shell-sidebar { position: sticky; top: 0; height: 100dvh; }
  /* 머리 높이를 헤더와 같게 둬서 두 경계선이 한 줄로 이어진다. 세로 여백을 두면 내용이 60px을 넘겨 어긋난다. */
  .ss-shell-sidebar > [data-slot="sidebar-header"] { justify-content: center; min-height: var(--ss-header-height); padding-block: 0; border-bottom: 1px solid var(--ss-sidebar-border); }
  .ss-shell-sidebar > [data-slot="sidebar-footer"] { gap: 0; padding-bottom: 1rem; border-top: 1px solid var(--ss-sidebar-border); }
  :is(.ss-shell-brand, .ss-shell-header-brand) > img { display: block; flex-shrink: 0; width: 1.75rem; height: 1.75rem; object-fit: contain; }
  .ss-shell-brand { display: flex; align-items: center; gap: .625rem; min-width: 0; padding: 0 .5rem; }
  .ss-shell-brand-text { display: grid; justify-items: start; gap: .125rem; min-width: 0; }
  .ss-shell-brand-name { max-width: 100%; margin: 0; overflow: hidden; color: inherit; font-size: .9375rem; font-weight: 650; letter-spacing: -.02em; line-height: 1.3; text-overflow: ellipsis; white-space: nowrap; }
  .ss-shell-nav { display: flex; flex-direction: column; gap: .125rem; }
  .ss-shell-nav > [data-slot="sidebar-group-label"]:not(:first-child) { margin-top: .75rem; }
  .ss-shell-account-summary { margin: 0; padding: .5rem .5rem 0; color: var(--ss-muted-foreground); font-size: .75rem; line-height: 1.4; overflow-wrap: anywhere; }
  .ss-shell-account-summary:empty { display: none; }

  /* ── 오른쪽 열과 헤더: (900px 이하 브랜드) | 상태 | 새로고침 | 계정 — dashboard-header-05 ── */
  .ss-shell-column { display: flex; flex-direction: column; min-width: 0; min-height: 100dvh; }
  .ss-shell-header {
    position: relative;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: .75rem;
    min-height: var(--ss-header-height);
    padding: 0 1.5rem;
    color: var(--ss-card-foreground);
    background: var(--ss-card);
    border-bottom: 1px solid var(--ss-border);
  }
  .ss-shell-header-brand { display: none; align-items: center; gap: .625rem; min-width: 0; min-height: 2.75rem; }
  .ss-shell-status { position: relative; flex: 1 1 auto; min-width: 0; }
  .ss-shell-actions { display: flex; flex: 0 0 auto; align-items: center; gap: .75rem; }
  .ss-shell-account { position: relative; flex: 0 0 auto; }

  /* 900px 이하 메뉴 버튼 — studio/navigation.js가 만들어 헤더 브랜드 뒤에 넣는다. 메뉴 아이콘 + 현재 화면 이름.
     "메뉴 · "는 .ss-sr-only라 읽히기만 한다. */
  .ss-shell-menu-trigger { justify-content: flex-start; max-width: 11rem; padding: 0 .75rem; }
  .ss-shell-menu-trigger::before {
    flex: 0 0 1rem;
    width: 1rem;
    height: .75rem;
    content: "";
    background:
      linear-gradient(currentColor 0 0) top / 100% 1.5px no-repeat,
      linear-gradient(currentColor 0 0) center / 100% 1.5px no-repeat,
      linear-gradient(currentColor 0 0) bottom / 100% 1.5px no-repeat;
  }
  .ss-shell-menu-current { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* 상태: 대시보드 컨트롤러의 요약 문장이 배지다. 다섯 상세는 원본 펼침(is-mobile-expanded)으로 연다. */
  .ss-shell-status-trigger { justify-content: flex-start; max-width: 100%; padding: 0 .75rem 0 .875rem; border-radius: 999px; }
  .ss-shell-status-trigger:has(.is-unready) { color: var(--ss-status-warning-fg); background: var(--ss-status-warning-bg); border-color: var(--ss-status-warning-fg); }
  .ss-shell-status-trigger::after {
    flex: 0 0 auto;
    width: .4375rem;
    height: .4375rem;
    margin: -.1875rem .125rem 0 0;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    content: "";
    transform: rotate(45deg);
  }
  .ss-shell-status-trigger[aria-expanded="true"]::after { margin-top: .1875rem; transform: rotate(-135deg); }
  .ss-shell-status-summary { position: relative; min-width: 0; padding-left: 1rem; overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
  /* 점은 글자색(currentColor)으로 칠한다. 상태 색 토큰은 글자색 토큰이라 background에 직접 쓰지 않는다(테스트). */
  .ss-shell-status-summary::before,
  .ss-shell-status-item::before {
    position: absolute;
    top: 50%;
    left: 0;
    width: .5rem;
    height: .5rem;
    color: var(--ss-muted-foreground);
    background: currentColor;
    border-radius: 999px;
    content: "";
    transform: translateY(-50%);
  }
  .ss-shell-status-item::before { top: .375rem; transform: none; }
  .ss-shell-status-summary.is-ready::before,
  .ss-shell-status-item.is-ready::before { color: var(--ss-status-success-fg); }
  .ss-shell-status-summary.is-unready::before,
  .ss-shell-status-item:is(.is-unready, .is-failed)::before { color: var(--ss-status-warning-fg); }
  .ss-shell-status-panel { position: absolute; top: calc(100% + .5rem); left: 0; z-index: 40; display: grid; gap: .5rem; width: min(20rem, calc(100vw - 2rem)); }
  .ss-shell-status-panel:not(.is-mobile-expanded) { display: none; }
  .ss-shell-panel-heading { margin: 0 0 .25rem; font-size: .8125rem; font-weight: 650; }
  .ss-shell-status-item { position: relative; display: block; padding-left: 1rem; font-size: .8125rem; line-height: 1.5; overflow-wrap: anywhere; }
  .ss-shell-panel-meta { margin: .25rem 0 0; padding-top: .625rem; color: var(--ss-muted-foreground); border-top: 1px solid var(--ss-border); font-size: .75rem; line-height: 1.5; }

  /* 새로고침과 계정. 로그아웃은 계정 메뉴 안에만 보인다(#logout-button은 원본 컨트롤러가 찾으므로 남긴다). */
  .ss-shell-refresh-status { max-width: 16rem; margin: 0; color: var(--ss-muted-foreground); font-size: .75rem; line-height: 1.4; text-align: right; }
  .ss-shell-refresh-compact,
  .ss-shell-logout { display: none; }
  .ss-shell-account-panel { position: absolute; top: calc(100% + .5rem); right: 0; z-index: 40; display: grid; gap: .75rem; width: min(18rem, calc(100vw - 2rem)); }
  .ss-shell-panel-summary { margin: 0; font-size: .875rem; line-height: 1.5; overflow-wrap: anywhere; }
  .ss-shell-account-panel > [data-slot="button"] { width: 100%; }

  /* ── 인증 오류·세션 만료 안내: 열 맨 위의 띠 ─────────────────────────── */
  #auth-error { padding: .75rem 1.5rem; border-width: 0 0 1px; border-radius: 0; font-weight: 600; }
  #session-expiry-banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem 1rem;
    padding: .75rem 1.5rem;
    color: var(--ss-status-warning-fg);
    background: var(--ss-status-warning-bg);
    border-width: 0 0 1px;
    border-color: var(--ss-status-warning-fg);
    border-radius: 0;
  }
  #session-expiry-banner.is-final { color: var(--ss-destructive); background: var(--ss-destructive-surface); border-color: var(--ss-destructive); }
  #session-expiry-banner [data-slot="alert-title"] { font-weight: 600; }
  #session-expiry-banner [data-slot="alert-description"] { color: inherit; }
  .ss-shell-session-text { flex: 1 1 18rem; min-width: 0; }
  .ss-shell-session-countdown { margin: 0; font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }

  /* ── 내용: 운영·파일럿과 같은 상자(최대 105rem, 여백 2rem; 900px 이하 위 1rem·옆 1.5rem; 640px 이하 1rem).
     화면 내부는 이 단계에서 바뀌지 않는다(계산 스타일 지문으로 확인한다). ── */
  .ss-shell-content { box-sizing: border-box; width: min(100%, 105rem); min-width: 0; padding: 2rem; }

  /* 1152px 이하: 새로고침 시각 문장은 화면에서 감추되 읽히게 둔다. 같은 문장이 상태 팝오버에도 있다. */
  @media (max-width: 1152px) {
    .ss-shell-refresh-status { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  }
  /* 900px 이하: 사이드바 대신 서랍. 헤더는 두 줄(44px씩, 최대 100px) — [브랜드 … 계정] / [메뉴 상태 … 새로고침]. */
  @media (max-width: 900px) {
    .ss-shell-app { display: block; }
    .ss-shell-sidebar { display: none; }
    .ss-shell-header {
      display: grid;
      grid-template-columns: auto minmax(0, 1fr) auto;
      grid-template-areas: "identity identity account" "menu status actions";
      gap: .125rem .5rem;
      padding: .25rem 1rem;
    }
    .ss-shell-header-brand { display: flex; grid-area: identity; }
    .ss-shell-header > .ss-shell-menu-trigger { grid-area: menu; }
    .ss-shell-status { position: static; grid-area: status; justify-self: start; max-width: 100%; }
    .ss-shell-actions { grid-area: actions; }
    .ss-shell-account { position: static; grid-area: account; justify-self: end; }
    .ss-shell-refresh-wide { display: none; }
    .ss-shell-refresh-compact { display: inline-flex; }
    .ss-shell-status-panel { top: calc(100% + .25rem); left: 1rem; width: min(22rem, calc(100% - 2rem)); }
    .ss-shell-account-panel { top: calc(100% + .25rem); right: 1rem; }
    :is(#auth-error, #session-expiry-banner) { padding-inline: 1rem; }
    .ss-shell-content { padding: 1rem 1.5rem 1.5rem; }
  }
  /* 640px 이하: 둘째 줄은 상태 문장을 먼저 다 보여주고 메뉴 이름만 말줄임한다(메뉴 아이콘은 남는다). */
  @media (max-width: 640px) {
    .ss-shell-header {
      grid-template-columns: minmax(44px, max-content) max-content minmax(0, 1fr) max-content;
      grid-template-areas: "identity identity identity account" "menu status . actions";
    }
    .ss-shell-header > .ss-shell-menu-trigger { justify-self: stretch; }
    .ss-shell-content { padding: 1rem; }
  }
  /* 360px 이하: 브랜드 이름은 감추되 읽히고(로고는 남는다), 상태는 점과 짧은 낱말이다. 낱말은 대체 글자가 비어
     두 번 읽히지 않는다. 버튼의 접근 이름은 컨트롤러의 온전한 문장이다. */
  @media (max-width: 22.5rem) {
    .ss-shell-header-brand .ss-shell-brand-name { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
    .ss-shell-status-summary { font-size: 0; }
    .ss-shell-status-summary::after { content: "확인 중" / ""; font-size: .8125rem; }
    .ss-shell-status-summary.is-ready::after { content: "정상" / ""; }
    .ss-shell-status-summary.is-unready::after { content: "확인 필요" / ""; }
  }

  /* 로그인 카드는 화면 전체의 남은 높이를 채운다. */
  body:has(#authenticated-view[hidden]) { display: flex; flex-direction: column; min-height: 100dvh; }
  body:has(#authenticated-view[hidden]) > main { display: flex; flex: 1; flex-direction: column; }
  .ss-auth {
    display: grid;
    flex: 1;
    place-items: center;
    box-sizing: border-box;
    width: 100%;
    margin: 0;
    padding: 2.5rem 1rem;
    color: var(--ss-foreground);
    background: var(--ss-muted);
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .ss-auth-status { color: var(--ss-muted-foreground); font-size: .875rem; }
  .ss-auth-card { width: 100%; max-width: 28rem; border-color: transparent; box-shadow: var(--ss-shadow-lg); }
  .ss-auth-card > [data-slot="card-header"] { justify-items: center; gap: 1rem; text-align: center; }
  .ss-auth-brand { display: flex; align-items: center; gap: .625rem; font-size: 1rem; font-weight: 600; }
  .ss-auth-brand > img { display: block; width: 2.25rem; height: 2.25rem; object-fit: contain; }
  .ss-auth-title { font-size: 1.5rem; letter-spacing: -.02em; line-height: 2rem; }
  .ss-auth-card > [data-slot="card-content"] { display: grid; gap: 1rem; }
  .ss-auth-form { display: grid; gap: 1rem; margin: 0; }
  .ss-auth-field { display: grid; gap: .5rem; }
  .ss-auth-form > [data-slot="button"] { width: 100%; margin-top: .5rem; }
  @media (max-width: 640px) {
    .ss-auth { place-items: start center; padding: 1.5rem 1rem; }
  }

  /* ── 900px 이하 메뉴 서랍 — studio/navigation.js가 만드는 Sheet(왼쪽). shadcn 모바일 Sidebar처럼 사이드바 색을
     쓴다. 헤더(30)와 Studio Sheet(1400) 위, 확인 창(2600) 아래다(테스트). ── */
  .ss-shell-drawer { z-index: 1800; }
  .ss-shell-drawer > [data-slot="sheet-content"] {
    gap: 0;
    width: var(--ss-sidebar-width-mobile);
    max-width: calc(100vw - 2rem);
    color: var(--ss-sidebar-foreground);
    background: var(--ss-sidebar);
    border-right-color: var(--ss-sidebar-border);
  }
  .ss-shell-drawer [data-slot="sheet-header"] { flex-direction: row; align-items: center; justify-content: space-between; padding: .5rem .5rem .5rem 1rem; border-bottom: 1px solid var(--ss-sidebar-border); }
  .ss-shell-drawer [data-slot="sheet-title"] { color: inherit; }
  .ss-shell-drawer .ss-shell-nav { flex: 1; min-height: 0; padding: .5rem; overflow-y: auto; overscroll-behavior: contain; }
}
