/* USV — layout.css — Reset + Body + 접근성 + 스크롤바 + 사이드바 + Topbar + 메인 레이아웃 */
/* ===================================================================
   2. Reset
   =================================================================== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ===================================================================
   3. Body 기본
   =================================================================== */
body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  display: flex;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===================================================================
   3b. 접근성 — 스킵 링크 + 포커스 가시성 (v2.1, Batch 4)
   =================================================================== */
.skip-link {
  position: absolute;
  top: -200px;
  left: var(--sp-4);
  padding: 8px 14px;
  background: var(--brand);
  color: #fff;
  font-weight: var(--fw-semibold);
  border-radius: var(--radius-md);
  text-decoration: none;
  z-index: var(--z-toast);
  transition: top var(--dur-base) var(--ease);
}
.skip-link:focus {
  top: var(--sp-2);
  outline: 3px solid var(--brand-soft);
  outline-offset: 2px;
}

/* 공용 포커스 스타일 — :focus-visible 미설정 요소의 최소 가시성 */
a:focus-visible,
.nav-item:focus-visible,
.tab-btn:focus-visible,
.kpi-card:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* v3.2.3-114: 비대화형 컨테이너의 포커스 아웃라인 제거.
   main[tabindex="-1"](스킵링크/페이지 포커스 타깃) 와 overflow 스크롤 영역
   (.card-body 등)은 클릭·스크롤·스크립트 포커스 시 브라우저가 검은색 사각
   아웃라인을 그렸음 — "본문 클릭 시 검은 테두리", "로드 직후 깜빡임" 의 원인.
   :focus 는 :focus-visible 을 포함하므로 두 경우 모두 억제된다.
   버튼·링크·입력·탭 등 실제 조작 요소의 포커스 링은 위 규칙대로 유지. */
main:focus,
[tabindex="-1"]:focus,
.card-body:focus,
[style*="overflow"]:focus {
  outline: none;
}

/* sr-only — 스크린리더 전용 라벨 */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ===================================================================
   4. 스크롤바 커스텀
   =================================================================== */
::-webkit-scrollbar        { width: 6px; height: 6px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  { background: var(--border-strong); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--muted-light); }

/* ===================================================================
   5. 사이드바 — 전체 구조
   =================================================================== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  position: sticky;
  top: 0;
  flex-shrink: 0;
  transition: width var(--dur-base) var(--ease);
  z-index: var(--z-sidebar);
  overflow: hidden;
}

/* 브랜드 블록 — topbar와 높이 정확히 일치시켜 하단 라인이 이어지도록 */
.sidebar-brand {
  height: var(--header-height);
  min-height: var(--header-height);
  padding: 0 var(--sp-5);
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  position: relative;
  flex-shrink: 0;
}

.logo-mark {
  width: 28px;
  height: 28px;
  min-width: 28px;
  background: linear-gradient(135deg, #2563EB, #3B82F6);
  color: #fff;
  border-radius: var(--radius-md);
  font-weight: 800;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-text {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  transition: opacity var(--dur-base) var(--ease);
}

.sidebar-collapse-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--dur-fast), color var(--dur-fast), transform var(--dur-base);
  flex-shrink: 0;
}
.sidebar-collapse-btn:hover {
  background: var(--bg);
  color: var(--text);
}

/* 내비게이션 영역 */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-2) var(--sp-3);
}

/* 섹션 레이블 */
.sidebar-section-label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: var(--sp-4) 10px var(--sp-1);
  white-space: nowrap;
  overflow: hidden;
  transition: opacity var(--dur-base) var(--ease);
}

/* 구분선 */
.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: var(--sp-2) 4px;
}

/* 네비게이션 아이템 */
.nav-item {
  display: flex;
  align-items: center;
  min-height: 40px;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  color: var(--text-sub);
  text-decoration: none;
  transition: background var(--dur-fast), color var(--dur-fast);
  margin-bottom: 2px;
  position: relative;
  white-space: nowrap;
  overflow: hidden;
}
.nav-item:hover {
  background: var(--bg);
  color: var(--text);
}
.nav-item.active {
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: var(--fw-semibold);
}

/* 아이콘 */
.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* 라벨 */
.nav-label {
  flex: 1;
  transition: opacity var(--dur-base) var(--ease);
}

/* 배지 */
.nav-badge {
  margin-left: auto;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--danger);
  color: #fff;
}

/* 툴팁 (collapsed 상태에서만 표시) */
.nav-tooltip {
  display: none;
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--text);
  color: var(--surface);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-xs);
  white-space: nowrap;
  z-index: var(--z-dropdown);
  pointer-events: none;
  box-shadow: var(--shadow-popover);
}
.nav-tooltip::before {
  content: '';
  position: absolute;
  right: 100%;
  top: 50%;
  transform: translateY(-50%);
  border: 5px solid transparent;
  border-right-color: var(--text);
}

/* 사이드바 푸터 — 사용자 정보(프로필)와 로그아웃을 별도 클릭 영역으로 분리 */
.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: var(--sp-3);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 4px;
}

.sidebar-user {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: var(--sp-2);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--dur-fast);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
}
.sidebar-user:hover {
  background: var(--bg);
}

.sidebar-logout-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.sidebar-logout-btn:hover {
  background: var(--danger-soft);
  color: var(--danger);
}
body[data-sidebar="collapsed"] .sidebar-logout-btn {
  display: none;
}

.user-avatar {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-weight: var(--fw-bold);
  font-size: var(--fs-base);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* sm 변형 (topbar용) */
.user-avatar.sm {
  width: 26px;
  height: 26px;
  min-width: 26px;
  font-size: var(--fs-xs);
}

.user-meta {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  transition: opacity var(--dur-base) var(--ease);
}

.user-name {
  font-size: var(--fs-base);
  font-weight: var(--fw-semibold);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: var(--fs-xs);
  color: var(--muted);
}

/* ===================================================================
   6. Collapsed 상태 — body[data-sidebar="collapsed"]
   =================================================================== */
body[data-sidebar="collapsed"] .sidebar {
  width: var(--sidebar-width-collapsed);
}
body[data-sidebar="collapsed"] .brand-text,
body[data-sidebar="collapsed"] .sidebar-section-label,
body[data-sidebar="collapsed"] .nav-label,
body[data-sidebar="collapsed"] .nav-badge,
body[data-sidebar="collapsed"] .user-meta {
  opacity: 0;
  pointer-events: none;
  width: 0;
  overflow: hidden;
}
body[data-sidebar="collapsed"] .nav-item {
  justify-content: center;
  padding: 8px 0;
}
body[data-sidebar="collapsed"] .nav-item:hover .nav-tooltip {
  display: block;
}
body[data-sidebar="collapsed"] .sidebar-collapse-btn svg {
  transform: rotate(180deg);
}
body[data-sidebar="collapsed"] .sidebar-user {
  justify-content: center;
  padding: var(--sp-2) 0;
}

/* 7. Legacy .sidebar .logo, .sidebar .nav-divider — 제거됨 (TD-7, v2.2) */

/* ===================================================================
   8. .main-wrap — 메인 콘텐츠 래퍼
   =================================================================== */
.main-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  min-width: 0;
}

/* ===================================================================
   9. Topbar (.topbar)
   =================================================================== */
.topbar {
  height: var(--header-height);
  min-height: var(--header-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--sp-5);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  flex-shrink: 0;
  z-index: var(--z-sticky-header);
  position: relative;
}

.topbar-toggle {
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-sub);
  transition: background var(--dur-fast);
  flex-shrink: 0;
}
.topbar-toggle:hover { background: var(--bg); }

.topbar-title {
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  color: var(--text);
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.topbar-breadcrumb {
  font-size: var(--fs-sm);
  color: var(--muted);
  margin-left: var(--sp-3);
}

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

.topbar-datetime {
  font-size: var(--fs-sm);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* 아이콘 버튼 */
.icon-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text-sub);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: background var(--dur-fast);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg); }

.notif-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--danger);
}

/* 유저 버튼 */
.topbar-user-btn {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  background: var(--surface);
  cursor: pointer;
  font-size: var(--fs-base);
  color: var(--text);
  font-family: inherit;
  transition: background var(--dur-fast);
  white-space: nowrap;
}
.topbar-user-btn:hover { background: var(--bg); }

/* 10. Legacy .top-header — 제거됨 (TD-7, v2.2) */

/* ===================================================================
   11. 페이지 레이아웃 (.page, .content-area)
   =================================================================== */
.page {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-6);
  position: relative;
}

/* 지도+패널 분할 레이아웃 */
.page.split {
  padding: 0;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

/* 통합 관제: 전체 지도 */
.page.map-full {
  padding: 0;
  position: relative;
  overflow: hidden;
}

/* 콘텐츠 영역 (legacy) */
.content-area {
  flex: 1;
  display: flex;
  overflow: hidden;
}
