/* ==========================================================================
   301cell — App Shell Layout
   좌측 고정 사이드바 + 상단 헤더 + Breadcrumb + 콘텐츠 + 우측 Drawer
   ========================================================================== */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns var(--dur-base) var(--ease);
}
.app[data-sidebar="collapsed"] { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }

/* 오프캔버스 배경막은 모바일 전용. 데스크톱에서 그리드 아이템으로 잡히면
   .main 이 두 번째 행으로 밀려나므로 반드시 display:none 이어야 한다. */
.sidebar-scrim { display: none; }

/* ==========================================================================
   Sidebar
   ========================================================================== */
.sidebar {
  grid-row: 1 / -1;
  position: sticky; top: 0; align-self: start;
  height: 100vh;
  display: flex; flex-direction: column;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  z-index: var(--z-sidebar);
  overflow: hidden;
}

.sidebar-brand {
  display: flex; align-items: center; gap: var(--sp-3);
  height: var(--header-h); flex: none;
  padding: 0 var(--sp-4);
  border-bottom: 1px solid var(--sidebar-border);
  color: var(--sidebar-fg-strong);
  text-decoration: none;
}
.sidebar-brand:hover { text-decoration: none; }
.sidebar-brand .mark {
  width: 28px; height: 28px; flex: none; border-radius: var(--r-sm);
  background: linear-gradient(135deg, var(--accent), var(--sidebar-active-bar));
  display: grid; place-items: center; color: #04202a; font-weight: var(--fw-bold); font-size: var(--fs-sm);
}
.sidebar-brand .name { font-weight: var(--fw-semibold); font-size: var(--fs-lg); letter-spacing: -0.01em; }
.sidebar-brand .sub  { font-size: var(--fs-2xs); color: var(--sidebar-muted); letter-spacing: 0.02em; }

.sidebar-search { padding: var(--sp-3) var(--sp-3) var(--sp-2); flex: none; }
.sidebar-search .input {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.1);
  color: var(--sidebar-fg-strong);
  height: 32px; font-size: var(--fs-sm);
}
.sidebar-search .input::placeholder { color: var(--sidebar-muted); }
.sidebar-search .input:focus { border-color: var(--sidebar-active-bar); box-shadow: 0 0 0 3px rgba(56,182,212,0.2); }

.sidebar-nav { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; padding: var(--sp-1) var(--sp-2) var(--sp-6); }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.16); background-clip: content-box; }

.nav-section {
  padding: var(--sp-4) var(--sp-3) var(--sp-1);
  font-size: var(--fs-2xs); font-weight: var(--fw-semibold);
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--sidebar-muted);
}

.nav-group { margin-bottom: 1px; }
.nav-item {
  display: flex; align-items: center; gap: var(--sp-3);
  width: 100%; padding: var(--sp-2) var(--sp-3);
  border: 0; background: transparent; border-radius: var(--r-sm);
  color: var(--sidebar-fg); font-size: var(--fs-sm); font-weight: var(--fw-normal);
  text-align: left; text-decoration: none; cursor: pointer; position: relative;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-item:hover { background: var(--sidebar-hover); color: var(--sidebar-fg-strong); text-decoration: none; }
.nav-item .num {
  flex: none; width: 20px; font-family: var(--font-mono); font-size: var(--fs-2xs);
  color: var(--sidebar-muted); text-align: center;
}
.nav-item .label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .chev { flex: none; transition: transform var(--dur-fast) var(--ease); color: var(--sidebar-muted); }
.nav-group[aria-expanded="true"] > .nav-item .chev { transform: rotate(90deg); }

.nav-item.is-active {
  background: var(--sidebar-active); color: var(--sidebar-fg-strong); font-weight: var(--fw-medium);
}
.nav-item.is-active::before {
  content: ""; position: absolute; left: -8px; top: 6px; bottom: 6px;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--sidebar-active-bar);
}
.nav-group.has-active > .nav-item { color: var(--sidebar-fg-strong); }

.nav-sub { display: none; padding: 2px 0 var(--sp-2) 0; }
.nav-group[aria-expanded="true"] > .nav-sub { display: block; }
.nav-sub .nav-item { padding-left: calc(var(--sp-3) + 20px + var(--sp-3)); font-size: var(--fs-sm); }
.nav-sub .nav-item::after {
  content: ""; position: absolute; left: calc(var(--sp-3) + 9px); top: 0; bottom: 0;
  width: 1px; background: var(--sidebar-border);
}

/* 미구현 화면 표시 — 링크는 살아있되 준비중 배지 */
.nav-item .soon {
  flex: none; font-size: 9px; line-height: 1; padding: 3px 4px; border-radius: var(--r-xs);
  background: rgba(255,255,255,0.08); color: var(--sidebar-muted); letter-spacing: 0.02em;
}
.nav-item.is-locked { opacity: 0.42; cursor: not-allowed; }
.nav-item.is-locked:hover { background: transparent; }

.sidebar-foot {
  flex: none; padding: var(--sp-2) var(--sp-2);
  border-top: 1px solid var(--sidebar-border);
  display: flex; align-items: center; gap: var(--sp-1);
}
.sidebar-foot .btn { color: var(--sidebar-fg); }
.sidebar-foot .btn:hover { background: var(--sidebar-hover); color: var(--sidebar-fg-strong); }

/* 접힘 상태 */
.app[data-sidebar="collapsed"] .sidebar-brand .txt,
.app[data-sidebar="collapsed"] .sidebar-search,
.app[data-sidebar="collapsed"] .nav-section,
.app[data-sidebar="collapsed"] .nav-item .label,
.app[data-sidebar="collapsed"] .nav-item .chev,
.app[data-sidebar="collapsed"] .nav-item .soon,
.app[data-sidebar="collapsed"] .nav-sub { display: none; }
.app[data-sidebar="collapsed"] .nav-item { justify-content: center; padding-inline: 0; }

/* 모바일: 오프캔버스 */
@media (max-width: 1024px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; left: 0; top: 0; width: var(--sidebar-w);
    transform: translateX(-100%);
    transition: transform var(--dur-base) var(--ease);
    box-shadow: var(--sh-xl);
  }
  .app[data-sidebar="open"] .sidebar { transform: none; }
  .sidebar-scrim {
    display: block;
    position: fixed; inset: 0; background: var(--overlay);
    z-index: calc(var(--z-sidebar) - 1); opacity: 0; pointer-events: none;
    transition: opacity var(--dur-base) var(--ease);
  }
  .app[data-sidebar="open"] .sidebar-scrim { opacity: 1; pointer-events: auto; }
}

/* ==========================================================================
   Main / Header
   ========================================================================== */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 100vh; }

.header {
  position: sticky; top: 0; z-index: var(--z-header);
  height: var(--header-h); flex: none;
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--sp-5);
  background: var(--header-bg);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--header-border);
}

.header-scope { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.scope-select {
  display: flex; align-items: center; gap: var(--sp-2);
  height: 32px; padding: 0 var(--sp-2) 0 var(--sp-3);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-sm); cursor: pointer; font-size: var(--fs-sm);
  color: var(--text-secondary); max-width: 220px;
}
.scope-select:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.scope-select .k { color: var(--text-faint); font-size: var(--fs-xs); flex: none; }
.scope-select .v { color: var(--text); font-weight: var(--fw-medium); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.global-search { flex: 1 1 auto; max-width: 460px; min-width: 0; }
.global-search .input { height: 32px; background: var(--surface-2); }
.global-search kbd {
  position: absolute; right: var(--sp-2); font-size: var(--fs-2xs); color: var(--text-faint);
  border: 1px solid var(--border); border-radius: var(--r-xs); padding: 1px 4px; background: var(--surface);
}

.header-actions { display: flex; align-items: center; gap: var(--sp-1); margin-left: auto; }

/* ---------- 테마 세그먼트 컨트롤 (전 페이지 필수) ---------- */
.theme-switch {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 2px; border-radius: var(--r-sm);
  background: var(--surface-3); border: 1px solid var(--border);
}
.theme-switch button {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  height: 26px; padding: 0 var(--sp-2);
  border: 0; border-radius: var(--r-xs); background: transparent;
  color: var(--text-muted); font-size: var(--fs-xs); font-weight: var(--fw-medium);
  cursor: pointer; transition: all var(--dur-fast) var(--ease);
}
.theme-switch button:hover { color: var(--text); background: var(--surface-hover); }
.theme-switch button[aria-checked="true"] {
  background: var(--surface); color: var(--text); box-shadow: var(--sh-xs);
}
.theme-switch button .icon { flex: none; }
@media (max-width: 1180px) { .theme-switch button .t { display: none; } .theme-switch button { padding-inline: var(--sp-2); } }

.icon-btn {
  position: relative; display: inline-grid; place-items: center;
  width: 32px; height: 32px; border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--text-secondary); cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn .dot {
  position: absolute; top: 5px; right: 5px; min-width: 15px; height: 15px; padding: 0 3px;
  border-radius: var(--r-full); background: var(--sig-danger); color: #fff;
  font-size: 9px; font-weight: var(--fw-bold); line-height: 15px; text-align: center;
  border: 2px solid var(--header-bg);
}

.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  display: grid; place-items: center; overflow: hidden;
  background: var(--primary-soft); color: var(--primary-soft-fg);
  font-size: var(--fs-xs); font-weight: var(--fw-semibold);
  border: 1px solid var(--border);
  user-select: none;
}
.avatar.has-photo { background: var(--surface-3); }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.is-lg { width: 44px; height: 44px; font-size: var(--fs-md); }
.user-chip {
  display: flex; align-items: center; gap: var(--sp-2); height: 34px;
  padding: 0 var(--sp-2); border: 0; background: transparent; border-radius: var(--r-sm);
  cursor: pointer; color: var(--text);
}
.user-chip:hover { background: var(--surface-hover); }
.user-chip .who { text-align: left; line-height: 1.15; }
.user-chip .who .n { font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.user-chip .who .r { font-size: var(--fs-2xs); color: var(--text-muted); }

/* ==========================================================================
   Breadcrumb / Page header
   ========================================================================== */
.subheader {
  position: sticky; top: var(--header-h); z-index: calc(var(--z-header) - 1);
  min-height: var(--subheader-h); flex: none;
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-5);
  background: var(--bg); border-bottom: 1px solid var(--border-subtle);
}
.breadcrumb { display: flex; align-items: center; gap: var(--sp-1); flex-wrap: wrap; font-size: var(--fs-xs); }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--text); }
.breadcrumb .sep { color: var(--text-faint); }
.breadcrumb [aria-current="page"] { color: var(--text); font-weight: var(--fw-medium); }

.content { flex: 1 1 auto; padding: var(--sp-5); width: 100%; max-width: var(--content-max); margin: 0 auto; }
.content-flush { padding: 0; max-width: none; }
.content-tall { display: flex; flex-direction: column; min-height: 0; }
@media (max-width: 640px) { .content, .header, .subheader { padding-inline: var(--sp-3); } }

.page-header { display: flex; align-items: flex-start; gap: var(--sp-4); margin-bottom: var(--sp-5); flex-wrap: wrap; }
.page-header .titles { min-width: 0; flex: 1 1 320px; }
.page-header h1 { font-size: var(--fs-2xl); letter-spacing: -0.015em; display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.page-header .desc { margin-top: var(--sp-1); font-size: var(--fs-sm); color: var(--text-muted); }
.page-header .actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }

/* ==========================================================================
   Drawer (우측 상세)
   ========================================================================== */
.drawer-scrim {
  position: fixed; inset: 0; background: var(--overlay); z-index: var(--z-drawer);
  opacity: 0; pointer-events: none; transition: opacity var(--dur-base) var(--ease);
}
.drawer-scrim.is-open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(var(--drawer-w), 100vw);
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: var(--sh-xl); z-index: calc(var(--z-drawer) + 1);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform var(--dur-slow) var(--ease);
}
.drawer.is-open { transform: none; }
.drawer.is-wide { width: min(760px, 100vw); }
.drawer-head {
  flex: none; display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border);
}
.drawer-head .t { font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.drawer-head .s { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 2px; }
.drawer-body { flex: 1 1 auto; overflow-y: auto; padding: var(--sp-5); }
.drawer-foot {
  flex: none; display: flex; align-items: center; gap: var(--sp-2); justify-content: flex-end;
  padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border); background: var(--surface-2);
}

/* ==========================================================================
   Modal
   ========================================================================== */
.modal-scrim {
  position: fixed; inset: 0; background: var(--overlay); z-index: var(--z-modal);
  display: grid; place-items: center; padding: var(--sp-5);
  opacity: 0; pointer-events: none; transition: opacity var(--dur-base) var(--ease);
}
.modal-scrim.is-open { opacity: 1; pointer-events: auto; }
.modal {
  width: min(560px, 100%); max-height: calc(100vh - var(--sp-10));
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--sh-xl);
  transform: translateY(8px) scale(0.99); transition: transform var(--dur-base) var(--ease);
}
.modal-scrim.is-open .modal { transform: none; }
.modal.is-lg { width: min(880px, 100%); }
.modal.is-sm { width: min(420px, 100%); }
.modal-head { flex: none; padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: var(--sp-3); }
.modal-head h2 { font-size: var(--fs-lg); }
.modal-body { flex: 1 1 auto; overflow-y: auto; padding: var(--sp-5); }
.modal-foot { flex: none; display: flex; align-items: center; justify-content: flex-end; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border); background: var(--surface-2);
  border-radius: 0 0 var(--r-lg) var(--r-lg); }

/* ==========================================================================
   Toast
   ========================================================================== */
.toast-host {
  position: fixed; right: var(--sp-5); bottom: var(--sp-5); z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: var(--sp-2); pointer-events: none;
  max-width: min(420px, calc(100vw - var(--sp-8)));
}
.toast {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--sig-info);
  border-radius: var(--r-md); box-shadow: var(--sh-lg);
  font-size: var(--fs-sm); pointer-events: auto;
  animation: toast-in var(--dur-base) var(--ease);
}
.toast.is-out { animation: toast-out var(--dur-base) var(--ease) forwards; }
.toast[data-tone="success"] { border-left-color: var(--sig-ok); }
.toast[data-tone="warning"] { border-left-color: var(--sig-warn); }
.toast[data-tone="danger"]  { border-left-color: var(--sig-danger); }
.toast .tt { font-weight: var(--fw-semibold); }
.toast .tm { color: var(--text-muted); font-size: var(--fs-xs); margin-top: 2px; }
@keyframes toast-in  { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }

/* ==========================================================================
   Print
   ========================================================================== */
@media print {
  .sidebar, .header, .subheader, .drawer, .drawer-scrim, .toast-host, .no-print { display: none !important; }
  .app { display: block; }
  .content { padding: 0; max-width: none; }
}
