/* USV — utilities.css — 유틸리티 클래스 + 반응형 미디어 쿼리 */
/* ===================================================================
   43–44. 유틸리티 클래스
   =================================================================== */
/* 텍스트 색상 */
.text-cyan    { color: var(--brand); }
.text-green   { color: var(--success); }
.text-red     { color: var(--danger); }
.text-yellow  { color: var(--warn); }
.text-muted   { color: var(--muted); }
.text-center  { text-align: center; }
.text-right   { text-align: right; }
.text-left    { text-align: left; }
.text-sm      { font-size: var(--fs-sm); }
.text-xs      { font-size: var(--fs-xs); }
.text-lg      { font-size: var(--fs-lg); }
.text-bold    { font-weight: var(--fw-bold); }
.text-semibold { font-weight: var(--fw-semibold); }

/* 플렉스 */
.flex           { display: flex; }
.flex-1         { flex: 1; }
.flex-col       { flex-direction: column; }
.items-center   { align-items: center; }
.items-start    { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-end    { justify-content: flex-end; }
.justify-center { justify-content: center; }

/* 그리드 */
.grid      { display: grid; }
.grid-2    { grid-template-columns: repeat(2, 1fr); }
.grid-3    { grid-template-columns: repeat(3, 1fr); }
.grid-4    { grid-template-columns: repeat(4, 1fr); }

/* 표시/숨김 */
.hidden  { display: none !important; }
.visible { visibility: visible; }
.invisible { visibility: hidden; }

/* D-L2 (v2.6.0) — 인라인 style="display:*" 대체용 유틸리티 (NO !important)
 * 요소의 "초기 상태"를 클래스로 선언하되, 이후 JS 가 `el.style.display=...` 로
 * 변경할 때 inline style 이 정상적으로 클래스를 덮어쓸 수 있도록 !important 미사용. */
.u-hidden       { display: none; }
.u-block        { display: block; }
.u-inline       { display: inline; }
.u-inline-block { display: inline-block; }
.u-flex         { display: flex; }
.u-inline-flex  { display: inline-flex; }
.u-grid         { display: grid; }
.u-flex-col     { flex-direction: column; }
.u-flex-row     { flex-direction: row; }

/* 마진 */
.mt-1 { margin-top: var(--sp-1); }
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }
.mt-6 { margin-top: var(--sp-6); }
.mt-8 { margin-top: var(--sp-2); }  /* legacy 호환: 기존 8px */

.mb-1 { margin-bottom: var(--sp-1); }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-3 { margin-bottom: var(--sp-3); }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-6 { margin-bottom: var(--sp-6); }
.mb-8 { margin-bottom: var(--sp-2); }  /* legacy 호환: 기존 8px */

/* 패딩 */
.p-2  { padding: var(--sp-2); }
.p-3  { padding: var(--sp-3); }
.p-4  { padding: var(--sp-4); }
.px-4 { padding-left: var(--sp-4); padding-right: var(--sp-4); }
.px-6 { padding-left: var(--sp-6); padding-right: var(--sp-6); }
.py-2 { padding-top: var(--sp-2); padding-bottom: var(--sp-2); }
.py-4 { padding-top: var(--sp-4); padding-bottom: var(--sp-4); }

/* 갭 */
.gap-2  { gap: var(--sp-2); }
.gap-3  { gap: var(--sp-3); }
.gap-4  { gap: var(--sp-4); }
.gap-6  { gap: var(--sp-2); }  /* legacy 호환: 기존 6px */
.gap-8  { gap: var(--sp-2); }  /* legacy 호환 */

/* 기타 */
.w-full  { width: 100%; }
.min-w-0 { min-width: 0; }
.overflow-hidden { overflow: hidden; }
.overflow-auto   { overflow: auto; }
.truncate        { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.whitespace-nowrap { white-space: nowrap; }
.rounded         { border-radius: var(--radius-md); }
.rounded-full    { border-radius: var(--radius-full); }
.border          { border: 1px solid var(--border); }
.border-top      { border-top: 1px solid var(--border); }
.border-bottom   { border-bottom: 1px solid var(--border); }
.cursor-pointer  { cursor: pointer; }

/* ===================================================================
   45. 반응형 미디어 쿼리
   =================================================================== */

/* 좁은 노트북 전용 — 900px 이하에서만 사이드바 자동 collapse (769~900) */
@media (max-width: 900px) and (min-width: 769px) {
  body:not([data-sidebar="collapsed"]) .sidebar {
    width: var(--sidebar-width-collapsed);
  }
  body:not([data-sidebar="collapsed"]) .brand-text,
  body:not([data-sidebar="collapsed"]) .sidebar-section-label,
  body:not([data-sidebar="collapsed"]) .nav-label,
  body:not([data-sidebar="collapsed"]) .nav-badge,
  body:not([data-sidebar="collapsed"]) .user-meta {
    opacity: 0;
    pointer-events: none;
    width: 0;
    overflow: hidden;
  }
  body:not([data-sidebar="collapsed"]) .nav-item {
    justify-content: center;
    padding: 8px 0;
  }
  body:not([data-sidebar="collapsed"]) .nav-item:hover .nav-tooltip {
    display: block;
  }
  body:not([data-sidebar="collapsed"]) .sidebar-user {
    justify-content: center;
    padding: var(--sp-2) 0;
  }
}

/* 태블릿/중간 크기 그리드만 별도 적용 (사이드바는 펼쳐진 상태 유지) */
@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
}

/* 모바일 드로어용 반투명 오버레이 */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: calc(var(--z-sidebar) - 1);
}
body[data-sidebar-open] .sidebar-overlay {
  display: block;
}

/* 모바일 — 사이드바를 드로어로 전환 */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform var(--dur-slow) var(--ease);
    width: var(--sidebar-width) !important;
    z-index: var(--z-sidebar);
  }
  /* 모바일에서 사이드바 열기: body[data-sidebar-open] 추가 필요 */
  body[data-sidebar-open] .sidebar {
    transform: translateX(0);
  }
  /* 라벨 등 무조건 표시 — !important 로 collapsed 상태보다 우선 */
  body[data-sidebar-open] .brand-text,
  body[data-sidebar-open] .sidebar-section-label,
  body[data-sidebar-open] .nav-label,
  body[data-sidebar-open] .nav-badge,
  body[data-sidebar-open] .user-meta {
    opacity: 1 !important;
    pointer-events: auto !important;
    width: auto !important;
    overflow: visible !important;
  }
  body[data-sidebar-open] .nav-item {
    justify-content: flex-start !important;
    padding: 8px 10px !important;
  }
  body[data-sidebar-open] .sidebar-logout-btn {
    display: inline-flex !important;
  }

  /* 강제 1/2 열로 재배치 — inline-style 페이지도 덮어씀 */
  .kpi-grid      { grid-template-columns: 1fr 1fr !important; }
  .form-row,
  .form-row3     { grid-template-columns: 1fr !important; }
  .dash-grid     { grid-template-columns: 1fr !important; }
  .shortcut-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .filter-grid-5 { grid-template-columns: 1fr 1fr !important; }

  /* 테이블 모바일 — 가로 스크롤 강제 (전화/액션까지 보이게) */
  .table-wrapper {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  .table-wrapper .tbl {
    min-width: 720px !important;
  }
  .tbl tbody td,
  .tbl thead th {
    white-space: nowrap;
  }

  .sidepanel {
    width: 100% !important;
    min-width: 0 !important;
    border-left: none;
    border-top: 1px solid var(--border);
  }

  /* split 레이아웃 — 지도(상단 45vh 고정) + 목록(하단 flex:1) */
  .page.split,
  .boat-split,
  .water-split,
  .settings-layout {
    flex-direction: column !important;
  }
  .page.split .map-section,
  .boat-split .map-section,
  .water-split .map-section {
    flex: 0 0 45vh !important;
    min-height: 280px;
  }
  .page.split .sidepanel,
  .boat-split .sidepanel,
  .water-split .sidepanel {
    flex: 1 1 auto !important;
    min-height: 0;
  }
  /* 환경설정 모바일: 왼쪽 세로 네비 → 상단 가로 스크롤 탭 (1줄) */
  .settings-layout .settings-nav {
    width: 100% !important;
    border-right: none !important;
    border-bottom: 1px solid var(--border);
    max-height: none !important;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px !important;
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    -webkit-overflow-scrolling: touch;
  }
  .settings-layout .settings-nav h3 {
    display: none;
  }
  .settings-layout .settings-nav a {
    flex-shrink: 0;
    padding: 8px 14px !important;
    margin-bottom: 0 !important;
    white-space: nowrap;
    font-size: 13px;
  }

  .topbar-datetime { display: none; }
  .topbar-title { font-size: 15px; }

  /* 모달은 화면 대부분 차지 */
  .modal {
    width: calc(100vw - 24px) !important;
    max-width: calc(100vw - 24px) !important;
  }

  /* =============================================================
     B-M1: 모바일 터치 타깃 44px 이상 (WCAG 2.5.5 / AAA)
     아이콘 전용 / 페이지네이션 / 모달 close / 내비 아이템까지 강제
     ============================================================= */
  .btn,
  .btn-icon,
  .btn-sm,
  .page-btn,
  .modal-close,
  .nav-item,
  .sidebar-logout-btn,
  .settings-layout .settings-nav a,
  .form-control,
  select,
  input[type="text"],
  input[type="search"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="tel"],
  input[type="url"],
  input[type="date"],
  input[type="time"],
  textarea {
    min-height: var(--touch-target-min);
  }
  /* 아이콘 전용 정사각 버튼은 너비도 확보 */
  .btn-icon,
  .modal-close {
    min-width: var(--touch-target-min);
  }
  /* 체크박스·라디오 자체는 키우지 않고, 클릭 영역만 확장 */
  .form-check,
  .form-radio {
    min-height: var(--touch-target-min);
    display: inline-flex;
    align-items: center;
  }
}

/* 태블릿/중간 크기: split 페이지의 sidepanel 폭 완화 */
@media (max-width: 1024px) and (min-width: 769px) {
  .sidepanel { width: 340px; min-width: 280px; }
}

/* v3.2.3-297 접근성: prefers-reduced-motion 전역 폴백 (WCAG 2.3.3)
   전정기관 민감 사용자 보호 — 모든 애니메이션/트랜지션 최소화.
   상시 펄스(긴급정지 FAB·연결 dot·보트 blink 등) 정지. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

