﻿  /* Tailwind CDN 로드 전에도 hidden 클래스가 동작하도록 보장 */
  .hidden { display: none !important; }

  :root {
    --gf-main: #E8820C;
    --gf-deep:    #1a1a1a;
    --gf-accent:  #5BA832;
    --gf-success: #22c55e;
    --gf-warning: #f59e0b;
    --gf-danger: #ef4444;
    --gf-purple: #5BA832;
    --gf-bg: #f1f5f9;
    --gf-card: #ffffff;
    --gf-border: #e2e8f0;
  }
  * { font-family: 'Pretendard', 'Noto Sans KR', sans-serif; box-sizing: border-box; }
  body { background: var(--gf-bg); margin: 0; overflow: hidden; }

  /* ── AUTH ── */
  #auth-overlay {
    position: fixed; inset: 0; background: var(--gf-deep);
    z-index: 2000; display: flex; align-items: center; justify-content: center;
    padding: 20px; transition: opacity .5s;
  }
  .auth-card {
    background: white; width: 100%; max-width: 420px; padding: 44px 40px;
    border-radius: 40px; text-align: center;
    box-shadow: 0 30px 60px -10px rgba(0,0,0,.6);
    border: 2px solid #e2e8f0;
  }
  .mascot-bounce { animation: mascotBounce 2.5s infinite ease-in-out; }
  @keyframes mascotBounce { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-12px)} }

  /* ── APP SHELL ── */
  #app-root { display: none; height: 100vh; width: 100vw; flex-direction: row; }
  #app-root.active { display: flex; }

  /* ── SIDEBAR ── */
  .sidebar {
    width: 256px; background: var(--gf-deep); color: white;
    display: flex; flex-direction: column; flex-shrink: 0; z-index: 50;
  }
  .sidebar-item {
    display: flex; align-items: center; gap: 12px; padding: 11px 20px;
    cursor: pointer; border-radius: 10px; margin: 2px 8px;
    transition: all .2s; color: #94a3b8; font-size: .85rem; font-weight: 600;
  }
  .sidebar-item:hover { background: rgba(255,255,255,.1); color: white; }
  .sidebar-item.active { background: rgba(255,255,255,.15); color: white; border-right: 3px solid var(--gf-main); }
  .sidebar-item i { width: 18px; text-align: center; }

  /* ── MOBILE NAV ── */
  .bottom-nav {
    position: absolute; bottom: 0; width: 100%; height: 68px;
    background: white; border-top: 1px solid var(--gf-border);
    display: flex; justify-content: space-around; align-items: center;
    z-index: 1000; padding-bottom: env(safe-area-inset-bottom);
  }
  .nav-item {
    display: flex; flex-direction: column; align-items: center;
    color: #94a3b8; font-size: .65rem; gap: 3px; cursor: pointer;
    flex: 1; border: none; background: none; font-weight: 700;
  }
  .nav-item.active { color: var(--gf-main); }
  .nav-item i { font-size: 1.3rem; }
  /* 사이드바 그룹 라벨 */
  .sidebar-group-label {
    font-size: 10px; font-weight: 700; letter-spacing: 2px;
    color: #64748b; text-transform: uppercase;
    padding: 16px 20px 6px;
  }

  /* 사이드바 접기/펼치기 */
  .sidebar { transition: width 0.25s ease; }
  .sidebar.collapsed { width: 68px !important; }
  .sidebar.collapsed .sidebar-item span,
  .sidebar.collapsed .sidebar-group-label,
  .sidebar.collapsed .sidebar-footer-content { display: none; }
  .sidebar.collapsed .sidebar-item { justify-content: center; padding: 11px 0; }
  .sidebar.collapsed .brand-text { display: none; }

  /* 전역 모바일 탭바 (mobile < 768px) */
  #mobile-tab-bar {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: 64px; background: white;
    border-top: 1px solid #e2e8f0;
    display: none; /* 기본 숨김 */
    justify-content: space-around; align-items: center;
    z-index: 1001; padding-bottom: env(safe-area-inset-bottom);
  }
  @media (max-width: 767px) {
    #mobile-tab-bar { display: flex; }
    .sidebar { display: none !important; }
    /* 각 screen의 per-screen bottom-nav는 숨김 (전역 탭바로 대체) */
    .bottom-nav { display: none !important; }
    /* 모바일에서 .page-body는 탭바 높이만큼 패딩 */
    .page-body { padding-bottom: calc(72px + env(safe-area-inset-bottom)) !important; }
  }
  @media (min-width: 768px) {
    #mobile-tab-bar { display: none !important; }
    #mobile-header { display: none !important; }
    #mobile-fab { display: none !important; }
    .bottom-nav { display: none !important; }
  }

  /* 모바일 탭바 아이템 */
  .mob-tab {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 3px; border: none; background: none;
    color: #94a3b8; font-size: 10px; font-weight: 700; cursor: pointer;
    min-height: 56px; padding: 0; transition: color 0.15s;
  }
  .mob-tab.active { color: #E8820C; }
  .mob-tab i { font-size: 20px; }

  /* FAB 버튼 */
  #mobile-fab {
    position: fixed; right: 20px;
    bottom: calc(72px + env(safe-area-inset-bottom) + 12px);
    width: 56px; height: 56px; border-radius: 50%;
    background: #E8820C; color: white; border: none;
    font-size: 24px; cursor: pointer; z-index: 1002;
    box-shadow: 0 4px 16px rgba(232,130,12,0.5);
    display: none;
    align-items: center; justify-content: center;
    transition: transform 0.2s;
  }
  #mobile-fab:active { transform: scale(0.92); }
  @media (max-width: 767px) {
    #mobile-fab { display: flex; }
  }

  /* 퀵 방문 바텀시트 */
  #quick-visit-sheet {
    position: fixed; inset: 0; z-index: 2000; display: none;
  }
  #quick-visit-sheet.open { display: block; }
  #quick-visit-backdrop {
    position: absolute; inset: 0; background: rgba(0,0,0,0.4);
  }
  #quick-visit-panel {
    position: absolute; bottom: 0; left: 0; right: 0;
    background: white; border-radius: 24px 24px 0 0;
    padding: 24px 20px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
    transform: translateY(100%);
    transition: transform 0.3s ease;
    max-height: 90vh; overflow-y: auto;
  }
  #quick-visit-sheet.open #quick-visit-panel { transform: translateY(0); }

  /* 사이드바 토글 버튼 */
  #sidebar-toggle-btn {
    position: absolute; top: 20px; right: -14px;
    width: 28px; height: 28px; border-radius: 50%;
    background: white; border: 1px solid #e2e8f0;
    cursor: pointer; z-index: 60;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; color: #64748b; box-shadow: 0 2px 6px rgba(0,0,0,.08);
  }
  @media (max-width: 767px) { #sidebar-toggle-btn { display: none; } }

  @media (max-width: 767px) {
    .content-scroll { padding-bottom: 80px !important; }
    /* 모바일 카드 최적화 */
    .card { border-radius: 14px; }
    .modal-box { margin: 12px; max-height: 90vh; overflow-y: auto; border-radius: 20px !important; }
    /* 버튼 터치 영역 확대 */
    .nav-item { min-height: 56px; touch-action: manipulation; }
    button, a { touch-action: manipulation; }
    /* 폰트 크기 모바일 최적화 */
    .text-3xl { font-size: 1.5rem; }
    .text-2xl { font-size: 1.25rem; }
    /* 테이블/그리드 모바일 대응 */
    .grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
  }

  /* iOS safe area */
  @supports(padding: max(0px)) {
    .bottom-nav {
      padding-bottom: max(8px, env(safe-area-inset-bottom));
      height: calc(68px + env(safe-area-inset-bottom));
    }
    .content-scroll {
      padding-bottom: calc(80px + env(safe-area-inset-bottom)) !important;
    }
  }

  /* 터치 피드백 */
  .card:active { transform: scale(0.98); transition: transform 0.1s; }
  button:active { opacity: 0.85; }
  .nav-item:active { background: rgba(232,130,12,0.1); }

  /* ── MAIN CONTENT ── */
  .main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
  .content-scroll { flex: 1; overflow-y: auto; }
  .content-scroll::-webkit-scrollbar { width: 5px; }
  .content-scroll::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

  /* ── SCREENS ── */
  .screen { display: none; flex-direction: column; height: 100%; }
  .screen.active { display: flex !important; }
  .page-body { flex: 1; overflow-y: auto; padding: 20px; }
  .page-body::-webkit-scrollbar { width: 5px; }
  .page-body::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
  @media (min-width: 768px) {
    .page-body { padding: 24px; }
  }

  /* ── CARDS ── */
  .card {
    background: var(--gf-card); border-radius: 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,.06), 0 4px 8px rgba(0,0,0,.04);
  }

  /* ── BADGES ── */
  .badge { padding: 3px 10px; border-radius: 99px; font-size: .65rem; font-weight: 800; }
  .badge-success { background: #dcfce7; color: #16a34a; }
  .badge-warning { background: #fef9c3; color: #ca8a04; }
  .badge-danger  { background: #fee2e2; color: #dc2626; }
  .badge-info    { background: #dbeafe; color: #2563eb; }
  .badge-purple  { background: #f3e8ff; color: #9333ea; }

  /* ── BUTTONS ── */
  .btn-primary {
    background: var(--gf-main); color: white; padding: 9px 18px;
    border-radius: 10px; font-weight: 700; cursor: pointer;
    border: none; display: inline-flex; align-items: center; gap: 6px;
    font-size: .82rem; transition: all .2s;
  }
  .btn-primary:hover { background: #0047a0; }
  .btn-accent {
    background: var(--gf-accent); color: white; padding: 9px 18px;
    border-radius: 10px; font-weight: 700; cursor: pointer;
    border: none; display: inline-flex; align-items: center; gap: 6px;
    font-size: .82rem; transition: opacity .2s;
  }
  .btn-accent:hover { opacity: .9; }
  .btn-ghost {
    background: transparent; color: #64748b; padding: 7px 14px;
    border-radius: 8px; font-weight: 600; cursor: pointer;
    border: 1px solid var(--gf-border); display: inline-flex; align-items: center; gap: 5px;
    font-size: .82rem; transition: background .2s;
  }
  .btn-ghost:hover { background: var(--gf-bg); }

  /* ── INPUTS ── */
  .inp {
    width: 100%; border: 2px solid var(--gf-border); border-radius: 12px;
    padding: 10px 14px; font-size: .85rem; outline: none; transition: border .2s;
    font-family: inherit;
  }
  .inp:focus { border-color: var(--gf-main); }
  select.inp { background: white; }

  /* ── MAP ── */
  #leaflet-map { height: 360px; border-radius: 12px; overflow: hidden; z-index: 1; }

  /* ── MODAL ── */
  .modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.5);
    z-index: 1000; display: flex; align-items: center; justify-content: center;
    padding: 16px;
  }
  .modal-box {
    background: white; border-radius: 24px; padding: 32px;
    max-width: 640px; width: 100%; max-height: 90vh; overflow-y: auto;
  }
  .modal-box::-webkit-scrollbar { width: 4px; }
  .modal-box::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

  /* ── TOAST ── */
  #toast {
    position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
    z-index: 9999; display: none; background: #1e293b; color: white;
    padding: 13px 26px; border-radius: 14px; font-weight: 700;
    box-shadow: 0 10px 25px rgba(0,0,0,.2); font-size: .85rem; white-space: nowrap;
  }

  /* ── KPI PRIORITY ── */
  .priority-high { border-left: 4px solid var(--gf-danger); }
  .priority-mid  { border-left: 4px solid var(--gf-warning); }
  .priority-low  { border-left: 4px solid var(--gf-success); }

  /* ── SCORE BAR ── */
  .score-bar { height: 7px; background: #e2e8f0; border-radius: 4px; overflow: hidden; }
  .score-fill { height: 100%; border-radius: 4px; }

  /* ── CHANNEL FILTER BUTTONS ── */
  .ch-btn {
    font-size: .72rem; font-weight: 700; padding: 5px 12px; border-radius: 99px;
    border: 1.5px solid var(--gf-border); cursor: pointer; background: white; color: #64748b;
    transition: all .2s;
  }
  .ch-btn.active { background: var(--gf-main); color: white; border-color: var(--gf-main); }
  .ch-btn:hover:not(.active) { background: var(--gf-bg); }

  /* ── PULSE ── */
  .pulse { animation: pulse 2s infinite; }
  @keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

  /* ── FADE IN ── */
  .fade-in { animation: fadeIn .35s ease; }
  @keyframes fadeIn { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:translateY(0)} }

  /* ── ROUTE STEP ── */
  .route-item { transition: all .25s; }
  .route-item:active { transform: scale(.97); opacity: .85; }
  /* Client tabs */
  .client-tab { transition: all .2s; }
  .client-tab.active-tab { }
  #admin-mode-btn { cursor: pointer; border: none; }

  /* ── 화면 레이아웃 명시적 보장 (오른쪽 쏠림 방지) ── */
  .screen { display:none; flex-direction:column; height:100%; width:100%; min-width:0; }
  .screen.active { display:flex !important; flex-direction:column !important; width:100% !important; height:100% !important; }
  .page-body { flex:1; overflow-y:auto; padding:20px; width:100%; min-width:0; box-sizing:border-box; }
  .page-body::-webkit-scrollbar { width: 5px; }
  .page-body::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
