/* ─── Portal Layout ──────────────────────── */
/* 변수, 리셋, 공통 컴포넌트는 common.css에서 관리 */

body {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── Portal Section (2열 셸) ─────────────
 * 기본 숨김 — 인증 상태(head `<html data-auth="in">`) 일 때만 즉시 표시.
 * FOUC 방지 — sessionStorage 토큰 유무로 첫 페인트 전 결정.
 * JS 가 `display:flex` 를 명시 설정하면 이 규칙을 덮어씀.
 * ───────────────────────────────────────── */
.portal-section {
  display: none;
  flex-direction: row;
  height: 100vh;
}
html[data-auth="in"] .portal-section { display: flex; }

/* ─── Shell Left (logo + sidebar) ─────── */
.shell__left {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  width: 240px;
  background: var(--color-sidebar);
  transition: width 0.25s ease;
}

.shell__left.is-collapsed { width: 60px; }

/* ─── Shell Right (topbar + main) ─────── */
.shell__right {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  position: relative;
}

/* ─── Shell Logo (좌측 상단) ──────────── */
.shell__logo {
  height: 53px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 20px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  flex-shrink: 0;
  background: var(--color-sidebar);
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.shell__logo svg { width: 22px; height: 22px; fill: #93c5fd; flex-shrink: 0; }

.shell__left.is-collapsed .shell__logo {
  padding: 0;
  justify-content: center;
}

.shell__left.is-collapsed .shell__logo-text { display: none; }

/* ─── Topbar (우측 상단) ──────────────── */
.topbar {
  height: 60px;
  background: var(--color-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  z-index: 100;
  gap: 16px;
}

.topbar__breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #cbd5e1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar__breadcrumb .breadcrumb__current {
  color: var(--color-bg);
  font-weight: 500;
}

.topbar__user {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #cbd5e1;
  font-size: 13px;
  flex-shrink: 0;
}

.topbar__user-role {
  background: var(--color-primary-glow, rgba(245, 185, 5, 0.12));
  color: var(--color-bg);
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.topbar__user-name { color: #e2e8f0; font-weight: 500; }

/* ─── 사용자 메뉴 버튼 (이름 클릭 → 드롭다운) ─── */
.topbar__user-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.topbar__user-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: 1px solid transparent;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: inherit;
  font: inherit;
}

.topbar__user-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: #475569;
}

.topbar__user-btn[aria-expanded="true"] {
  background: rgba(255, 255, 255, 0.08);
  border-color: #64748b;
}

.topbar__user-arrow {
  width: 12px;
  height: 12px;
  fill: #94a3b8;
  transition: transform 0.15s ease;
}

.topbar__user-btn[aria-expanded="true"] .topbar__user-arrow {
  transform: rotate(180deg);
}

.topbar__user-menu {
  top: calc(100% + 6px);
  right: 0;
  min-width: 160px;
  padding: 6px;
}

.topbar__user-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--fs-sm);
  color: var(--color-text);
  text-align: left;
}

.topbar__user-menu-item:hover {
  background: var(--color-table-hover);
}

.topbar__user-menu-item i {
  width: 16px;
  color: var(--color-muted);
}

.topbar__theme-toggle {
  background: none;
  border: 1px solid #475569;
  color: #94a3b8;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.topbar__theme-toggle:hover {
  border-color: #64748b;
  color: #e2e8f0;
  transform: scale(1.1) rotate(15deg);
}

/* ─── Sidebar ─────────────────────────── */
.sidebar {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  position: relative;
  min-height: 0;
}

/* ─── Sidebar Toggle (shell__right 왼쪽 edge) ─── */
.sidebar__toggle {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  width: 16px;
  height: 40px;
  border-radius: 0 4px 4px 0;
  background: var(--color-border);
  border: none;
  color: #94a3b8;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 11;
}

.sidebar__toggle:hover { background: var(--color-primary); color: var(--color-bg); }

.sidebar__toggle svg { width: 11px; height: 11px; fill: currentColor; transition: transform 0.25s; }

.portal-section:has(.shell__left.is-collapsed) .sidebar__toggle svg { transform: rotate(180deg); }

/* ─── Module Selector ─────────────────── */
.sidebar__modules {
  padding: 8px 10px 4px;
}

.module-selected {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  background: #313131;
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.module-selected:hover { background: #151515; }

.module-selected svg.module-selected__icon {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex-shrink: 0;
  margin-right: 8px;
}

.module-selected__label { flex: 1; text-align: center; }

.module-selected__arrow {
  width: 16px;
  height: 16px;
  fill: currentColor;
  transition: transform 0.2s;
  flex-shrink: 0;
}

.sidebar__modules.open .module-selected__arrow { transform: rotate(180deg); }

.module-selected--empty {
  background: rgba(255,255,255,0.08);
  color: #94a3b8;
}

.module-selected--empty:hover { background: rgba(255,255,255,0.12); }

/* ─── Module List ─────────────────────── */
.module-list {
  display: none;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.sidebar__modules.open .module-list { display: flex; }

.module-tab {
  flex: 1 1 calc(50% - 3px);
  padding: 8px 4px;
  border: none;
  border-radius: var(--radius-md);
  background: rgba(255,255,255,0.04);
  color: var(--color-muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  line-height: 1.3;
}

.module-tab svg {
  display: block;
  margin: 0 auto 4px;
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.module-tab:hover { background: var(--color-sidebar-hover); color: #e0e0f0; }

.module-tab.active {
  background: var(--color-sidebar-active);
  color: #ffffff;
}

.module-tab.disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

/* ─── Sidebar Collapsed: Module ───────── */
.shell__left.is-collapsed .sidebar__modules { padding: 8px 6px 4px; }
.shell__left.is-collapsed .module-selected__label { display: none; }
.shell__left.is-collapsed .module-selected__arrow { display: none; }
.shell__left.is-collapsed .module-selected { justify-content: center; padding: 8px 4px; }
.shell__left.is-collapsed .module-list { gap: 4px; }
.shell__left.is-collapsed .module-tab { flex: 1 1 100%; padding: 8px 4px; }
.shell__left.is-collapsed .module-tab span { display: none; }

/* ─── Sidebar Divider ─────────────────── */
.sidebar__divider {
  height: 1px;
  background: var(--color-border);
  margin: 4px 14px 8px;
}

.shell__left.is-collapsed .sidebar__divider { margin: 4px 6px 8px; }

/* ─── Menu Groups ─────────────────────── */
.sidebar__nav { flex: 1; padding: 0 0 16px; overflow: hidden; }

.menu-group { margin-bottom: 4px; }

.menu-group__title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 16px 9px 20px;
  color: #c8c8e0;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s;
  user-select: none;
}

.menu-group__title:hover { background: var(--color-sidebar-hover); }

.menu-group__title.active {
  background: var(--color-sidebar-active);
  color: #fff;
}

.menu-group__arrow {
  width: 16px;
  height: 16px;
  fill: #64748b;
  transition: transform 0.2s;
}

.menu-group.open .menu-group__arrow { transform: rotate(90deg); }

.menu-group__items {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease;
}

.menu-group.open .menu-group__items { max-height: 300px; }

/* ─── Menu Items ──────────────────────── */
.menu-item {
  display: block;
  padding: 7px 16px 7px 40px;
  color: #94a3b8;
  font-size: 12px;
  text-decoration: none;
  transition: all 0.12s;
  cursor: pointer;
  border-left: 3px solid transparent;
}

.menu-item:hover {
  background: var(--color-sidebar-hover);
  color: #e0e0f0;
}

.menu-item.active {
  color: #ffffff;
  background: var(--color-sidebar-active);
  border-left-color: #ffffff;
}

.menu-sub {
  padding-left: 52px;
  font-size: 11px;
  color: var(--color-muted);
}

.menu-sub:hover { color: #b0b0c8; }
.menu-sub.active { color: var(--color-primary); border-left-color: var(--color-primary); }

/* ─── Sidebar Collapsed: Menu ─────────── */
.shell__left.is-collapsed .menu-group__title {
  padding: 9px 0;
  justify-content: center;
  font-size: 0;
}

.shell__left.is-collapsed .menu-group__title-icon {
  font-size: 11px;
  display: block;
  text-align: center;
  color: inherit;
}

.shell__left.is-collapsed .menu-group__title-text { display: none; }
.shell__left.is-collapsed .menu-group__arrow { display: none; }

.shell__left.is-collapsed .menu-item {
  padding: 6px 0;
  font-size: 0;
  text-align: center;
  border-left: none;
}

.shell__left.is-collapsed .menu-item::before {
  content: attr(data-short);
  font-size: 10px;
  display: block;
}

.shell__left.is-collapsed .menu-sub { display: none; }

/* ─── Sidebar Collapsed: Tooltip ──────── */
.shell__left.is-collapsed .menu-group__title,
.shell__left.is-collapsed .menu-item {
  position: relative;
}

.shell__left.is-collapsed .menu-group__title:hover::after,
.shell__left.is-collapsed .menu-item:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 8px;
  background: rgba(0,0,0,0.85);
  color: #fff;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  z-index: 200;
  pointer-events: none;
}

/* ─── Main Content ────────────────────── */
/* 구조: main > page-header (고정) + [id="{project}PageContent"] (flex:1)
 * page-content class 는 common.css 에서 공통 정의. */
.main {
  flex: 1;
  padding: 24px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow: hidden;
}

.main > .page-header {
  flex: 0 0 auto;
}

/* project 컨텐츠 ID(#portalPageContent, #webzinePageContent, #newsletterPageContent)
 * 는 ID 를 JS 쿼리 용도로만 사용하고, 레이아웃은 `.page-content` 공통 클래스에서 담당한다.
 * 내부에 selector-bar 등 상단 고정 요소가 있을 수 있어 flex column 으로 쌓는다. */
.main > [id$="PageContent"] {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ─── Statusbar (우측 하단) ────────────── */
.statusbar {
  height: 28px;
  flex-shrink: 0;
  background: var(--color-card-bg);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-size: var(--fs-xs);
  color: var(--color-muted);
}

.statusbar__message,
.statusbar__aux {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* .page-header → common.css §공통 컴포넌트 로 이관됨 */

/* ─── Stat Cards ──────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.stat-card__label {
  font-size: 12px;
  color: #64748b;
  margin-bottom: 6px;
}

.stat-card__value {
  font-size: 24px;
  font-weight: 600;
  color: var(--color-text);
}

.stat-card__sub {
  font-size: 11px;
  color: var(--color-success);
  margin-top: 4px;
}

/* 카드, 테이블, 배지 → common.css */

/* ─── Responsive ──────────────────────── */
@media (max-width: 1024px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .shell__left { width: 60px; }
  .shell__logo { padding: 0; justify-content: center; }
  .shell__logo-text { display: none; }
  .sidebar .sidebar__modules { padding: 12px 6px 8px; gap: 4px; }
  .sidebar .module-tab span { display: none; }
  .sidebar .module-tab { flex: 1 1 100%; padding: 8px 4px; }
  .sidebar .menu-group__title { padding: 9px 0; justify-content: center; font-size: 0; }
  .sidebar .menu-group__title-icon { font-size: 11px; display: block; text-align: center; }
  .sidebar .menu-group__title-text { display: none; }
  .sidebar .menu-group__arrow { display: none; }
  .sidebar .menu-item { padding: 6px 0; font-size: 0; text-align: center; border-left: none; }
  .sidebar .menu-item::before { content: attr(data-short); font-size: 10px; display: block; }
  .sidebar__toggle { display: none; }
  .stat-grid { grid-template-columns: 1fr; }
}
