/* ===== MOBILE ERP — 공통 (탑바·탭바·드로어·레이아웃) =====
   페이지별 전용 스타일은 mobile-chat/contract/product.css 참조
   ============================================================ */

/* 모바일 요소는 기본 숨김 */
.mobile-topbar,
.mobile-tab-bar,
.mobile-drawer,
.mobile-drawer-overlay {
  display: none;
}

/* 데스크탑 (769px 이상) — 모바일 요소 숨김, 데스크탑 요소 표시 */
@media (min-width: 769px) {
  .mobile-topbar,
  .mobile-tab-bar,
  .mobile-drawer,
  .mobile-drawer-overlay { display: none !important; }
  .sidebar,
  .sidebar--new { display: flex !important; }
  .top-bar { display: grid !important; }
}

html:not(.is-mobile) .dashboard-shell--new {
  display: grid !important;
  grid-template-columns: auto 1fr !important;
}

/* 데스크탑(min-width)에서도 동일하게 숨김 (호환성) */
@media (min-width: 769px) {
  .mobile-topbar,
  .mobile-tab-bar { display: none !important; }
}

/* iframe 임베드 모드 (embed=1) — 쉘 크롬 전부 숨김 */
html.is-embed .mobile-topbar,
html.is-embed .mobile-tab-bar,
html.is-embed .mobile-drawer,
html.is-embed .mobile-drawer-overlay,
html.is-embed .sidebar,
html.is-embed .top-bar { display: none !important; }
html.is-embed .dashboard-shell--new { height: 100dvh; overflow: hidden; }
html.is-embed .main-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
html.is-embed .main-shell--new { flex: 1; overflow-y: auto; padding: 0 !important; }

@media (max-width: 768px) {

  /* ─── 레이아웃 리셋 ─────────────────────────────────────────────────────── */

  .dashboard-shell--new {
    display: flex !important;
    flex-direction: column !important;
    grid-template-columns: none !important;
    height: 100dvh;
    overflow: hidden;
  }

  /* 사이드바 완전 숨김 */
  .dashboard-shell--new .sidebar,
  .sidebar--new {
    display: none !important;
  }

  /* 메인 영역 풀너비 */
  .main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
  }

  /* 데스크탑 탑바 숨김 */
  .top-bar {
    display: none !important;
  }

  /* 스크롤 영역 */
  .main-shell--new {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(var(--mobile-tabbar-height) + env(safe-area-inset-bottom)) !important;
  }

  /* ─── 모바일 요소 표시 ──────────────────────────────────────────────────── */

  .mobile-topbar  { display: flex !important; }
  .mobile-tab-bar { display: flex !important; }

  /* ─── 입력란 iOS 자동 확대 방지 (font-size < 16px → zoom) ──────────────── */
  input[type="text"],
  input[type="search"],
  input[type="number"],
  input[type="tel"],
  input[type="email"],
  input[type="date"],
  textarea {
    font-size: var(--font-size-xl) !important;
  }
  /* select는 14px — 주변 텍스트와 통일 (iOS는 zoom 없음) */
  select {
    font-size: var(--font-size-lg) !important;
  }

  /* ─── 패널 레이아웃 조정 ────────────────────────────────────────────────── */

  /* 좌우 패널 분할 → 세로 스택 */
  .panel-split,
  .panel-row {
    flex-direction: column !important;
  }

  /* 패널 최소 너비 해제 */
  .panel-left,
  .panel-right,
  .panel-main,
  .list-panel,
  .detail-panel {
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    flex: none !important;
  }


  /* ─── 설정 페이지 ───────────────────────────────────────────────────────── */
  .settings-page-shell {
    display: flex !important;
    flex-direction: column !important;
    gap: var(--panel-gap) !important;
  }

  /* ─── 정산 페이지 ───────────────────────────────────────────────────────── */
  .settlement-page-shell {
    flex-direction: column !important;
    overflow-y: auto;
  }
  .settlement-page-shell .pls-grid-panel {
    display: flex !important;
    flex: 0 0 auto;
    max-height: 45vh;
    overflow-y: auto;
    border-bottom: none;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06);
  }
  .settlement-page-shell .panel-slot {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
  }
  .settlement-page-shell .panel-slot .panel--form {
    height: 100%;
    overflow-y: auto;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE TOP BAR
   ═══════════════════════════════════════════════════════════════════════════ */

.mobile-topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  height: var(--mobile-topbar-height);
  min-height: var(--mobile-topbar-height);
  padding: 0 var(--m-pad-x);
  background: var(--m-card-bg);
  border-bottom: 1px solid var(--m-divider);
  justify-content: space-between;
  gap: var(--m-gap);
  flex-shrink: 0;
  width: 100%;
  box-sizing: border-box;
}

/* 필터 버튼 — 페이지별 기능 정의 후 다시 활성화 예정 */
.mobile-topbar__filter-btn { display: none !important; }

.mobile-topbar__left,
.mobile-topbar__right,
.mobile-topbar__center {
  display: flex;
  align-items: center;
  min-width: 0;
}
.mobile-topbar__left:empty,
.mobile-topbar__right:empty,
.mobile-topbar__center:empty {
  display: none;
}
.mobile-topbar__user-info {
  display: none;
}
.mobile-topbar__company {
  color: var(--m-text-primary);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100px;
}
.mobile-topbar__name {
  color: var(--m-text-secondary);
  white-space: nowrap;
}
.mobile-topbar__rank {
  color: var(--m-text-tertiary);
  white-space: nowrap;
  font-size: var(--m-font-sub);
}
.mobile-topbar__company:empty,
.mobile-topbar__name:empty,
.mobile-topbar__rank:empty { display: none; }

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE BOTTOM TAB BAR
   ═══════════════════════════════════════════════════════════════════════════ */

.mobile-tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  align-items: stretch;
  justify-content: space-around;
  height: calc(var(--mobile-tabbar-height) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--m-card-bg);
  border-top: 1px solid var(--m-divider);
  contain: layout style paint;
}

.mobile-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  flex: 1;
  border: none;
  background: transparent;
  text-decoration: none;
  color: var(--m-text-tertiary);
  font-size: var(--m-font-sub);
  font-weight: 500;
  cursor: pointer;
  position: relative;
  padding: 6px 0 0;
  -webkit-tap-highlight-color: transparent;
  transition: color var(--transition-fast);
}

.mobile-tab.is-active { color: var(--m-accent); font-weight: 600; }
.mobile-tab svg { width: 22px; height: 22px; stroke-width: 1.5; }
.mobile-tab.is-active svg { stroke-width: 2; }

.mobile-tab__label { font-size: var(--m-font-sub); line-height: 1; }

.mobile-tab__badge {
  position: absolute;
  top: 4px;
  left: calc(50% + 4px);
  min-width: 16px;
  height: 16px;
  padding: 0 var(--space-1);
  border-radius: var(--radius-pill);
  background: #ef4444;
  color: #fff;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-heavy);
  display: flex;
  align-items: center;
  justify-content: center;
}

.mobile-tab__badge[hidden] { display: none !important; }

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE DRAWER
   ═══════════════════════════════════════════════════════════════════════════ */

.mobile-drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(15, 23, 42, 0.4);
}
.mobile-drawer-overlay[hidden] { display: none !important; }

.mobile-drawer {
  position: fixed;
  top: var(--mobile-topbar-height);
  right: 0;
  bottom: 0;
  z-index: 301;
  width: var(--mobile-drawer-width);
  background: #fff;
  box-shadow: -2px 0 12px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
}
.mobile-drawer[hidden] { display: none !important; }

.mobile-drawer__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: var(--space-5) 14px var(--space-4) 18px;
  padding-top: max(20px, env(safe-area-inset-top));
}

.mobile-drawer__head-info {
  flex: 1;
  min-width: 0;
}

.mobile-drawer__close {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: var(--radius-md);
  background: #f1f5f9;
  color: #64748b;
  cursor: pointer;
  padding: 0;
  margin-top: 2px;
  -webkit-tap-highlight-color: transparent;
}
.mobile-drawer__close:active { background: #e2e8f0; }

.mobile-drawer__company {
  font-size: var(--font-size-base);
  color: #64748b;
  font-weight: var(--font-weight-strong);
  line-height: 1.4;
}

.mobile-drawer__name {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-heavy);
  color: #0f172a;
  margin-top: var(--space-1);
  line-height: 1.3;
}

.mobile-drawer__role {
  font-size: var(--font-size-base);
  color: #94a3b8;
  margin-top: 3px;
  line-height: 1.4;
}

.mobile-drawer__section-divider {
  height: 1px;
  background: #f1f5f9;
  margin: var(--space-1) 0;
}

.mobile-drawer__body {
  flex: 1;
  padding: var(--space-2) 0;
  overflow-y: auto;
}

.mobile-drawer__item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: var(--height-2xl);
  padding: 0 var(--space-4);
  border: none;
  background: transparent;
  color: #1e293b;
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-strong);
  text-decoration: none;
  cursor: pointer;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}
.mobile-drawer__item:active { background: #f8fafc; }
.mobile-drawer__item svg { color: #64748b; flex-shrink: 0; }
.mobile-drawer__item.is-active { color: #1b2a4a; font-weight: var(--font-weight-heavy); background: #f0f4ff; }
.mobile-drawer__item.is-active svg { color: #1b2a4a; }
.mobile-drawer__item--danger { color: #ef4444; }
.mobile-drawer__item--danger svg { color: #ef4444; }

.mobile-drawer__foot {
  padding: var(--space-2) 0;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.mobile-drawer__version {
  font-size: var(--font-size-sm);
  color: #cbd5e1;
  text-align: center;
  padding: var(--space-2) 0 var(--space-1);
}

/* ═══════════════════════════════════════════════════════════════════════════
   SHARED MOBILE LIST CARD — 대화·계약 목록 공통 카드
   ═══════════════════════════════════════════════════════════════════════════ */

.m-list-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 12px var(--space-4);
  border-bottom: 1px solid var(--m-divider, #f2f4f6);
  background: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  min-width: 0;
}
.m-list-card:active { background: #f8fafc; }
.m-list-card.is-active { background: #f0f4ff; }

.m-list-card__avatar {
  width: var(--height-lg); height: var(--height-lg);
  border-radius: 10px;
  background: #f1f5f9;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: #64748b;
}
.m-list-card__avatar--pending {
  background: #fff7ed;
  color: #f59e0b;
}
.m-list-card__avatar--done {
  background: #ecfdf5;
  color: #10b981;
}
.m-list-card__unread {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #3b82f6;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}

.m-list-card__body {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: var(--space-1);
}

.m-list-card__main {
  display: flex; align-items: center; gap: 6px; min-width: 0;
}
.m-list-card__name {
  flex: 1; min-width: 0;
  font-size: var(--font-size-lg); font-weight: 600; color: #0f172a;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.m-list-card__sub {
  display: flex; align-items: center; gap: 6px; min-width: 0;
}
.m-list-card__info {
  flex: 1; min-width: 0;
  font-size: var(--font-size-base); color: #64748b;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.m-list-card__date {
  flex-shrink: 0;
  font-size: var(--font-size-sm); color: #94a3b8;
}

/* 뱃지 공통 */
.m-list-badge {
  flex-shrink: 0;
  height: 20px; padding: 0 7px; border-radius: var(--radius-pill);
  font-size: var(--font-size-sm); font-weight: 600;
  display: inline-flex; align-items: center;
  white-space: nowrap;
}
.m-list-badge--blue    { background: #3b82f6; color: #fff; }
.m-list-badge--green   { background: #10b981; color: #fff; }
.m-list-badge--red     { background: #ef4444; color: #fff; }
.m-list-badge--yellow  { background: #f59e0b; color: #fff; }
.m-list-badge--gray    { background: #94a3b8; color: #fff; }

/* 빈 목록 */
.m-list-empty {
  padding: 60px var(--space-5);
  text-align: center;
  font-size: var(--font-size-lg); color: #94a3b8;
}

/* ═══════════════════════════════════════════════════════════════════════════
   공통 모바일 필터 오버레이/사이드바 (대화·계약 페이지)
   ═══════════════════════════════════════════════════════════════════════════ */

/* 데스크탑(>768px)에선 모바일 필터 사이드바/오버레이는 절대 표시 안 함
   다른 클래스(.catalog-sidebar 등)가 같이 붙어도 !important로 차단 */
.m-filter-overlay { display: none !important; }
.m-filter-sidebar { display: none !important; }

@media (max-width: 768px) {
  .m-filter-overlay {
    display: none !important;
    position: fixed;
    top: var(--mobile-topbar-height);
    left: 0;
    right: 0;
    bottom: calc(var(--mobile-tabbar-height) + env(safe-area-inset-bottom));
    z-index: 90;
    background: rgba(15, 23, 42, 0.4);
  }
  .m-filter-overlay.is-open { display: block !important; }

  .m-filter-sidebar {
    display: block !important;
    position: fixed;
    right: 0;
    top: var(--mobile-topbar-height);
    bottom: calc(var(--mobile-tabbar-height) + env(safe-area-inset-bottom));
    z-index: 91;
    width: 280px;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    will-change: transform;
    border-left: 1px solid #e2e8f0;
    background: #fff;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .m-filter-sidebar.is-open {
    transform: translateX(0);
    box-shadow: -2px 0 10px rgba(15, 23, 42, 0.08);
  }
}

