/* styles/app.css — 레이아웃/컴포넌트. 색·간격은 tokens.css 변수만 사용 */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { overflow-x: clip; } /* 페이지 가로 넘침 방지 (sticky 유지) */
body {
  font-family: "Pretendard", "Malgun Gothic", -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }

/* ── 헤더 ─────────────────────────────────────────── */
.appbar {
  background: linear-gradient(135deg, var(--brand-900), var(--brand-700));
  color: var(--text-inv);
  padding: var(--sp-3) var(--sp-4);
  display: flex; align-items: center; gap: var(--sp-4);
  flex-wrap: wrap;
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow);
}
.appbar h1 { font-size: 17px; margin: 0; font-weight: 800; letter-spacing: -0.02em; }
.appbar .sub { font-size: 12px; opacity: 0.82; margin-top: 2px; }
.appbar .brand { display: flex; flex-direction: column; }
.appbar .spacer { flex: 1; }

/* 모드 토글 */
.mode-toggle { display: flex; background: rgba(255,255,255,0.14); border-radius: 999px; padding: 3px; }
.mode-toggle button {
  border: 0; background: transparent; color: var(--text-inv);
  padding: 7px 16px; border-radius: 999px; font-size: 13px; font-weight: 700; opacity: 0.75;
  display: flex; align-items: center; gap: 6px;
}
.mode-toggle button.active { background: var(--surface); color: var(--brand-800); opacity: 1; }
.mode-badge { display: inline-flex; align-items: center; gap: 6px; background: rgba(255,255,255,0.16); color: #fff; border: 1px solid rgba(255,255,255,0.25); padding: 8px 16px; border-radius: 999px; font-size: 14px; font-weight: 700; cursor: pointer; }
.mode-badge.is-on { background: var(--surface); color: var(--brand-800); border-color: transparent; }
.mode-badge i { font-size: 16px; }

/* ── 검색/필터 바 ─────────────────────────────────── */
.toolbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: var(--sp-3) var(--sp-4);
  display: flex; flex-direction: column; gap: var(--sp-3);
  position: sticky; top: 58px; z-index: 40;
}
.search-row { display: flex; gap: var(--sp-2); align-items: center; }
.search-box {
  position: relative;
  flex: 1; display: flex; align-items: center; gap: var(--sp-2);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 9px var(--sp-3); max-width: 420px;
}
.search-box i { color: var(--text-dim); }
.search-box input { flex: 1; border: 0; background: transparent; font-size: 15px; outline: none; color: var(--text); }

/* 검색 자동완성 드롭다운 */
.search-suggest {
  display: none; position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 60;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); max-height: 320px; overflow-y: auto; padding: 4px;
}
.search-suggest.show { display: block; }
.suggest-item { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: var(--radius-sm); cursor: pointer; }
.suggest-item:hover, .suggest-item.active { background: var(--surface-2); }
.suggest-item .s-name { flex: 1; font-size: 14px; font-weight: 600; color: var(--text); }
.suggest-item .s-tag { font-size: 11px; font-weight: 700; color: #fff; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.search-summary { font-size: 13px; color: var(--text-dim); white-space: nowrap; }
.search-summary b { color: var(--brand-700); }

.chips { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; }
.chips .chips-label { font-size: 12px; color: var(--text-dim); font-weight: 700; margin-right: 2px; }
.chip {
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip .dot { width: 10px; height: 10px; border-radius: 50%; }
.chip.active { color: var(--text-inv); border-color: transparent; }
.chip.mine-on { box-shadow: inset 0 0 0 2px var(--surface), 0 0 0 2px currentColor; }

/* ── 본문 레이아웃 ─────────────────────────────────── */
/* 지도는 항상 전체 폭, 방문 패널은 우측 서랍(오버레이) */
.layout { padding: var(--sp-4); }
.map-wrap { position: relative; min-width: 0; }

/* ── 지도 (원본 배치도 재현: 납작·밀착·흰 보통글씨) ── */
.map-frame {
  background: var(--map-bg);
  border: 1px solid var(--map-frame);
  border-radius: 16px; padding: 16px 18px;
  box-shadow: var(--shadow);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch; /* 모바일 관성 스크롤 */
}
/* 확대/축소 래퍼 — transform 스케일 + 스크롤 영역 보정 */
.map-scaler { position: relative; overflow: hidden; }
.map-zoom { position: relative; transform-origin: 0 0; width: var(--map-w); }

/* 탭하여 크게 보기 힌트 · 전체화면 닫기 · 가로 회전 힌트 (기본 숨김) */
.tap-hint { display: none; }
.fs-close { display: none; }
.fs-rotate { display: none; }
.fs-hint { display: none; }

/* 지도 전체화면(크게 보기) — 가로 전체 맞춤 */
.map-wrap.fullscreen { position: fixed; inset: 0; z-index: 200; background: var(--surface); padding: 6px; margin: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.map-wrap.fullscreen #map { height: 100%; width: 100%; display: flex; align-items: center; justify-content: center; }
.map-wrap.fullscreen .map-frame { max-height: 100%; overflow: visible; border-radius: 8px; }
.map-wrap.fullscreen .fs-close,
.map-wrap.fullscreen .fs-rotate {
  display: flex; position: fixed; top: 14px; z-index: 210;
  width: 46px; height: 46px; border-radius: 50%; border: 0;
  background: rgba(16,40,61,0.78); color: #fff; font-size: 20px; align-items: center; justify-content: center; cursor: pointer;
}
.map-wrap.fullscreen .fs-close { right: 14px; }
.map-wrap.fullscreen .fs-rotate { right: 68px; }
.map-wrap.fullscreen.rotated .fs-rotate { background: var(--brand-700); }
/* 가로 보기: 지도 전체를 90° 회전해 세로 화면에서도 가로로 크게 (회전 잠금 대응) */
.map-wrap.fullscreen.rotated #map { transform: rotate(90deg); }
.map-wrap.fullscreen.rotated .fs-hint { display: none; }
.map-wrap.fullscreen .fs-hint {
  display: flex; align-items: center; gap: 6px;
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 205;
  max-width: 90vw; white-space: nowrap;
  background: rgba(16,40,61,0.86); color: #fff; padding: 8px 14px; border-radius: 999px;
  font-size: 13px; font-weight: 700; pointer-events: none; box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
@media (orientation: landscape) { .map-wrap.fullscreen .fs-hint { display: none; } }

@media (max-width: 820px) {
  /* 프리뷰(작게 맞춘) 상태에서는 지도 스크롤 잠금 → 탭이 전체화면 열기로 */
  .map-wrap:not(.fullscreen) .map-frame { overflow: hidden; cursor: zoom-in; }
  /* 탭 힌트 (하단 중앙, 부스 안 가리게) */
  .map-wrap:not(.fullscreen) .tap-hint {
    display: flex; align-items: center; gap: 5px;
    position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); z-index: 20;
    background: rgba(16,40,61,0.86); color: #fff; padding: 7px 14px;
    border-radius: 999px; font-size: 12px; font-weight: 700; pointer-events: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  }
}

/* ── 방문 동선 및 메모 : 우측 서랍 ─────────────────── */
.side-panel {
  position: fixed; top: 0; right: 0; height: 100dvh; width: 380px; max-width: 90vw;
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: -10px 0 30px rgba(11,58,111,0.2);
  display: flex; flex-direction: column; z-index: 130;
  transform: translateX(100%); visibility: hidden;
  transition: transform 0.28s ease, visibility 0s linear 0.28s;
}
.side-panel.open { transform: translateX(0); visibility: visible; transition: transform 0.28s ease, visibility 0s; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); }
.drawer-title { font-size: 15px; font-weight: 800; color: var(--brand-800); display: inline-flex; align-items: center; gap: 6px; }
.drawer-x { border: 0; background: var(--surface-2); color: var(--text); width: 34px; height: 34px; border-radius: 8px; font-size: 17px; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.panel-backdrop { position: fixed; inset: 0; background: rgba(11,40,61,0.4); z-index: 120; opacity: 0; pointer-events: none; transition: opacity 0.25s; }
.panel-backdrop.show { opacity: 1; pointer-events: auto; }
/* 공통 열 트랙: [좌벽] c1 c2 |통로| c3 c4 |통로| c5 c6 |통로| c7 c8 [우벽] (13트랙) */
.map-cols {
  grid-template-columns:
    var(--wall-w)
    minmax(var(--booth-col), 1fr) minmax(var(--booth-col), 1fr) var(--aisle-x)
    minmax(var(--booth-col), 1fr) minmax(var(--booth-col), 1fr) var(--aisle-x)
    minmax(var(--booth-col), 1fr) minmax(var(--booth-col), 1fr) var(--aisle-x)
    minmax(var(--booth-col), 1fr) minmax(var(--booth-col), 1fr)
    var(--wall-w);
  column-gap: var(--col-gap);
  min-width: 1180px;
}

/* 상단 부스 행 — 열 트랙에 맞춰 정렬 */
.top-row { display: grid; margin-bottom: var(--aisle-y); align-items: stretch; }
.top-cluster { grid-column: 11 / 14; display: flex; gap: 4px; align-items: stretch; }
.top-cluster .top-booth { flex: 1 1 auto; padding: 6px 4px; font-size: 10.5px; }

/* 본문 그리드 = 좌우 벽면 + 부스 + 행 통로 (밴드 그룹: [1·2][3·4·5][6·7]) */
.map-body {
  display: grid;
  grid-template-rows:
    auto auto var(--aisle-y)   /* 밴드1, 2, 통로 */
    auto var(--aisle-y)        /* 밴드3, 통로 */
    auto auto var(--aisle-y)   /* 밴드4, 5, 통로 */
    auto auto;                 /* 밴드6, 7 */
  row-gap: var(--row-gap);
}
.wall-cell {
  background: var(--wall-bg); color: var(--text-inv); border-radius: 4px;
  display: flex; align-items: center; justify-content: center; text-align: center;
  writing-mode: vertical-rl; padding: 8px 2px; font-size: 12.5px; font-weight: 400; letter-spacing: 0.05em;
  cursor: pointer; transition: filter 0.08s;
}
.wall-cell:hover { filter: brightness(1.08); }
.wall-cell.match { background: var(--match-bg); color: var(--match-text); font-weight: 700; box-shadow: inset 0 0 0 2px var(--match-ring); }
.wall-cell.dim { background: var(--dim-bg); color: var(--dim-text); }
.wall-cell.filtered { background: var(--fcolor, var(--wall-bg)); color: #fff; }
.wall-cell.mine { box-shadow: inset 3px 0 0 var(--mine, #fff); }

/* 셀 = 세로로 쌓인 lane 묶음(블록). 내부 부스는 작은 간격으로 나뉨 */
.cell { display: flex; flex-direction: column; gap: var(--cell-gap); position: relative; }
/* lane = 한 가로줄. 나란한 두 대학도 작은 간격으로 나뉨 */
.lane { display: flex; gap: var(--cell-gap); }

/* 기둥(■) 셀: lane1 우측이 통로(회색 기둥) */
.lane.pillar-single .pillar-slot { flex: 0 0 38%; justify-content: flex-start; padding-left: 6px; } /* 학교 1개 → 옆칸 크게 차지 */
.lane.pillar-pair .pillar-slot { flex: 0 0 15px; justify-content: center; }                         /* 학교 2개 → 우측에 작게 */
.pillar-slot { display: flex; align-items: center; }
.pillar-sq { width: 9px; height: 9px; background: #74879e; border-radius: 2px; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.28); }

.booth {
  flex: 1 1 0; min-width: 0;
  background: var(--booth-bg); color: var(--booth-text);
  border-radius: 4px; padding: 7px 4px;
  font-size: 12.5px; font-weight: 400; text-align: center; line-height: 1.18;
  min-height: 34px;
  display: flex; align-items: center; justify-content: center; gap: 3px;
  transition: filter 0.08s;
  position: relative; word-break: keep-all;
}
/* 나란한 두 대학은 폭이 좁아 글씨 축소 */
.lane .booth:not(:only-child) { font-size: 11px; padding: 6px 2px; letter-spacing: -0.02em; }
.booth:hover { filter: brightness(1.08); }
.booth .nm { max-width: 100%; }

.booth.match { background: var(--match-bg); color: var(--match-text); font-weight: 700; z-index: 1; box-shadow: inset 0 0 0 2px var(--match-ring); }
.booth.dim { background: var(--dim-bg); color: var(--dim-text); }
/* 권역 필터 선택: 해당 권역 색으로 강조 (자연스럽게 눈에 띄게) */
.booth.filtered { background: var(--fcolor, var(--booth-bg)); color: #fff; font-weight: 600; z-index: 1; box-shadow: 0 0 0 2px rgba(255,255,255,0.25), 0 2px 6px rgba(0,0,0,0.25); }
/* 영업 담당권역(mine): 글씨는 흰색 유지, 하단 권역색 띠로만 표시 (가독성) */
.booth.mine { box-shadow: inset 0 -3px 0 var(--mine, #fff); }

.booth .flag { position: absolute; top: 1px; right: 2px; font-size: 10px; color: #ffe08a; }
.booth .marks { position: absolute; top: 1px; left: 2px; display: flex; gap: 2px; font-size: 10px; }
.booth .marks .plan-m { color: #ffd24a; }
.booth .marks .visit-m { color: #8ce99a; }

.top-booth {
  border-radius: 4px; padding: 8px 9px; font-size: 12px; font-weight: 400;
  text-align: center; white-space: nowrap; display: flex; align-items: center; min-height: 32px;
}
.top-booth.univ { background: var(--booth-bg); color: var(--booth-text); }
.top-booth.facility { background: var(--facility-bg); color: var(--facility-text); }
.top-booth.univ.match { background: var(--match-bg); color: var(--match-text); font-weight: 700; }
.top-booth.univ.dim { background: var(--dim-bg); color: var(--dim-text); }
.top-booth.univ.filtered { background: var(--fcolor, var(--booth-bg)); color: #fff; font-weight: 600; }
.lane .top-booth + .top-booth { box-shadow: inset 1.5px 0 0 var(--divider); }
.top-row .lane { align-items: stretch; }

/* 방문 동선 경로선 오버레이 */
.route-overlay { position: absolute; top: 0; left: 0; pointer-events: none; z-index: 6; }
.route-line { fill: none; stroke: #f76707; stroke-width: 3.5; stroke-linejoin: round; stroke-linecap: round; stroke-dasharray: 8 6; filter: drop-shadow(0 1px 1.5px rgba(0,0,0,0.25)); }
.route-dot { fill: #f76707; stroke: #fff; stroke-width: 2; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3)); }
.route-num { fill: #16283d; font-size: 12px; font-weight: 800; text-anchor: middle; dominant-baseline: central; }

/* 동선 패널 헤더/토글 */
.route-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 10px; border-bottom: 1px dashed var(--border); margin-bottom: 6px; }
.route-opt { font-size: 12.5px; font-weight: 700; color: var(--brand-700); display: inline-flex; align-items: center; gap: 4px; }
.route-toggle { font-size: 12px; color: var(--text-dim); display: inline-flex; align-items: center; gap: 4px; cursor: pointer; user-select: none; }

/* 입구/출구 — 열 트랙 정렬 */
.gates { display: grid; margin-top: 14px; align-items: start; }
.gate { color: var(--text-dim); font-size: 13px; font-weight: 800; display: flex; flex-direction: column; align-items: center; }
.gate .gate-bar { width: 100%; height: 8px; border-radius: 4px; background: #b7c4d5; margin-bottom: 6px; }
.gate.entrance i { color: #2f9e44; }
.gate.exit i { color: #e03131; }

/* ── 사이드 패널 ───────────────────────────────────── */
.panel-tabs { display: flex; border-bottom: 1px solid var(--border); }
.panel-tabs button { flex: 1; border: 0; background: transparent; padding: 11px 0; font-size: 13px; font-weight: 700; color: var(--text-dim); border-bottom: 2px solid transparent; }
.panel-tabs button.active { color: var(--brand-700); border-bottom-color: var(--brand-700); }
.panel-body { overflow-y: auto; padding: var(--sp-3); flex: 1; }
.panel-empty { color: var(--text-dim); font-size: 13px; text-align: center; padding: 28px 8px; line-height: 1.6; }

.route-item { display: flex; align-items: center; gap: var(--sp-2); padding: 9px var(--sp-2); border-radius: var(--radius-sm); }
.route-item:hover { background: var(--surface-2); }
.route-item .seq { width: 22px; height: 22px; border-radius: 50%; background: var(--brand-700); color: #fff; font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.route-item .r-name { flex: 1; font-size: 14px; font-weight: 600; }
.route-item .r-name.done { text-decoration: line-through; color: var(--text-dim); }
.route-item .r-region { font-size: 11px; padding: 2px 7px; border-radius: 999px; color: #fff; font-weight: 700; }
.route-item .icon-btn { border: 0; background: transparent; color: var(--text-dim); padding: 4px; font-size: 16px; }
.route-item .icon-btn.on { color: var(--brand-600, var(--brand-700)); }

/* 메모 카드 (방문 예정 학교마다 메모 입력) */
.note-item { padding: 10px 6px; border-bottom: 1px solid var(--border); }
.note-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.note-name { font-size: 14px; font-weight: 700; cursor: pointer; }
.note-input { width: 100%; min-height: 46px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 9px; font-family: inherit; font-size: 13px; resize: vertical; }
.note-input:focus { outline: none; border-color: var(--brand-500); }

.panel-actions { padding: var(--sp-3); border-top: 1px solid var(--border); display: flex; gap: var(--sp-2); }
.btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: var(--radius-sm); padding: 9px 12px; font-size: 13px; font-weight: 700; display: inline-flex; align-items: center; gap: 6px; justify-content: center; }
.btn.primary { background: var(--brand-700); color: #fff; border-color: transparent; }
.btn.danger { color: #e03131; }
.btn.block { flex: 1; }

/* ── 모달 (부스 상세 / 내보내기) ───────────────────── */
.modal-back { position: fixed; inset: 0; background: rgba(11,58,111,0.45); display: flex; align-items: center; justify-content: center; z-index: 400; padding: var(--sp-4); }
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 460px; max-height: 88vh; display: flex; flex-direction: column; overflow: hidden; }
/* 가로(회전) 모드: 팝업도 90° 회전해 세로 화면을 옆으로 든 상태에서 똑바로 보이게 */
.modal-back.rotated .modal { transform: rotate(90deg); width: min(88vh, 460px); max-width: 88vh; max-height: 84vw; }
.modal-head { padding: var(--sp-4); border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; gap: var(--sp-2); }
.modal-head .m-title { font-size: 18px; font-weight: 800; flex: 1; }
.modal-head .m-close { border: 0; background: transparent; font-size: 22px; color: var(--text-dim); }
.modal-head .m-region { font-size: 12px; padding: 3px 9px; border-radius: 999px; color: #fff; font-weight: 700; align-self: center; }
.modal-body { padding: var(--sp-4); overflow-y: auto; }
.modal-body label { font-size: 13px; font-weight: 700; color: var(--text-dim); display: block; margin-bottom: 6px; }
.modal-body textarea { width: 100%; min-height: 110px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; font-family: inherit; font-size: 14px; resize: vertical; }
.modal-foot { padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border); display: flex; gap: var(--sp-2); }
.toggle-btns { display: flex; gap: var(--sp-2); margin-bottom: var(--sp-4); }

.export-pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--sp-3); font-family: "Consolas", monospace; font-size: 13px; white-space: pre-wrap; line-height: 1.55; max-height: 40vh; overflow-y: auto; }
.warn { color: #e8590c; font-size: 13px; display: flex; gap: 6px; align-items: center; margin-bottom: var(--sp-2); font-weight: 600; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--brand-900); color: #fff; padding: 11px 20px; border-radius: 999px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow-lg); z-index: 200; opacity: 0; transition: opacity 0.2s, transform 0.2s; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

.legend { display: flex; gap: var(--sp-3); flex-wrap: wrap; font-size: 12px; color: var(--text-dim); align-items: center; }
.legend .lg { display: inline-flex; align-items: center; gap: 5px; }
.legend .sw { width: 14px; height: 14px; border-radius: 4px; }

/* ── 반응형 ────────────────────────────────────────── */
@media (max-width: 960px) {
  .layout { padding: var(--sp-2); }
}
/* 태블릿·모바일: 지도 자동 맞춤(스크롤 최소화), 부스는 살짝 촘촘하게 */
@media (max-width: 760px) {
  :root { --booth-col: 88px; --col-gap: 9px; --row-gap: 11px; --aisle-x: 10px; --aisle-y: 16px; --map-w: 940px; }
  .map-cols { min-width: 940px; }
  .map-frame { padding: 8px; }
  .booth { font-size: 11.5px; padding: 7px 3px; }
  .toolbar { top: 54px; padding: var(--sp-2) var(--sp-3); }
  .legend { display: none; }
  /* 권역 필터: 한 줄 가로 스와이프 (세로 공간 절약) */
  .chips { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 3px; scrollbar-width: none; }
  .chips::-webkit-scrollbar { display: none; }
  .chips-label, .chip { flex: 0 0 auto; }
  .chips-label { position: sticky; left: 0; background: var(--surface); padding-right: 6px; z-index: 1; }
}
@media (max-width: 620px) {
  .appbar { padding: var(--sp-2) var(--sp-3); gap: var(--sp-2); }
  .appbar h1 { font-size: 14px; }
  .appbar .sub { font-size: 11px; }
  .search-summary { display: none; }
  .search-box { max-width: none; }
  .chips { gap: 6px; }
  .chip { padding: 6px 11px; font-size: 13px; } /* 손가락 탭 여유 */
  .modal { max-width: 100%; }
}
