/* V3 공용 컴포넌트 */

/* 레이아웃 */
.layout { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }

/* 모바일 햄버거 + 백드롭 (기본 숨김) */
.mob-menu-btn { display: none; }
.mob-backdrop { display: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  /* 사이드바 = 슬라이드인 드로어 */
  .side {
    position: fixed; top: 0; left: 0;
    width: 280px; max-width: 80vw; height: 100vh;
    overflow-y: auto;
    z-index: 9999;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,.1);
  }
  .side.open { transform: translateX(0); }
  /* 햄버거 버튼 */
  .mob-menu-btn {
    display: inline-flex; align-items: center; justify-content: center;
    position: fixed; top: 12px; left: 12px;
    z-index: 9998;
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--peach); color: #fff;
    font-size: 22px; line-height: 1;
    border: none; cursor: pointer;
    box-shadow: 0 4px 12px rgba(232,152,130,.4);
  }
  .mob-menu-btn:active { transform: scale(.95); }
  /* 백드롭 */
  .mob-backdrop.show {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 9997;
    animation: fade-in .2s;
  }
}

.side { padding: 26px 18px; background: var(--surface); border-right: 1px solid var(--border); }
.side .brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 22px; border-bottom: 1px dashed var(--border); margin-bottom: 14px; }
.side .brand-mark { width: 44px; height: 44px; border-radius: var(--r-md); background: linear-gradient(135deg, var(--peach), var(--peach-2)); display: flex; align-items: center; justify-content: center; font-size: 24px; box-shadow: var(--sh-cta); }
.side .brand b { font-size: 16px; font-weight: 800; }
.side .brand small { color: var(--muted); font-size: 11.5px; display: block; }
.side .nav-title { padding: 14px 12px 6px; font-size: 12px; color: var(--faint); font-weight: 700; letter-spacing: .04em; }
.side .nav a { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: var(--r-md); margin-bottom: 2px; color: var(--text); font-weight: 500; font-size: 14.5px; }
.side .nav a:hover { background: var(--surface-2); color: var(--peach-2); }
.side .nav a.active { background: linear-gradient(135deg, #fff1e3, #fde3ce); color: var(--peach-2); font-weight: 700; }
.side .nav a .c { margin-left: auto; font-size: 12px; background: var(--cream); color: var(--peach-2); padding: 2px 8px; border-radius: 10px; font-weight: 700; }
.side .nav a.active .c { background: var(--peach); color: #fff; }

main { padding: 28px 36px; min-width: 0; }
@media (max-width: 900px) {
  html, body { overflow-x: hidden; }
  main { padding: 60px 14px 16px; max-width: 100vw; overflow-x: hidden; }
}

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { line-height: 1.2; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
@media (max-width: 700px) {
  .page-head { flex-direction: column; align-items: stretch; gap: 8px; }
  .page-head h1 { font-size: 22px; }
  .page-head .flex { flex-wrap: wrap; gap: 6px; }
}

/* Hero 카드 */
.hero { background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 50%, #ffccbc 100%); border-radius: var(--r-xl); padding: 28px 32px; margin-bottom: 20px; position: relative; overflow: hidden; }
.hero::after { content: "🐾"; position: absolute; right: -20px; bottom: -10px; font-size: 160px; opacity: .1; transform: rotate(-15deg); }
.hero h1 { font-size: 26px; margin-bottom: 6px; }
.hero p { color: var(--muted); }
.hero .actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; position: relative; z-index: 1; }

/* 카드 */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); padding: 22px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; }
.panel-h { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.panel-h h3 { display: flex; align-items: center; gap: 8px; }
.panel-h .link { color: var(--peach-2); font-weight: 600; font-size: 12.5px; cursor: pointer; }
.panel-b { padding: 18px 22px; }
.panel-b.nopad { padding: 0; }

/* Pill (배지) */
.pill { display: inline-block; padding: 3px 10px; border-radius: var(--r-sm); font-size: 11px; font-weight: 700; }
.p-c { background: #e3f2fd; color: var(--sky); }
.p-h { background: var(--cream); color: var(--peach-2); }
.p-k { background: #e8f5e9; color: var(--sage-2); }
.p-t { background: #ede7f6; color: var(--lilac); }
.p-done { background: #e8f5e9; color: var(--sage-2); }
.p-hold { background: var(--cream); color: var(--peach-2); }
.p-pend { background: #e3f2fd; color: var(--sky); }
.p-cnc  { background: #ffebee; color: var(--berry); }

/* 탭 (pill 형) */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.tab { padding: 9px 16px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: 13.5px; font-weight: 600; color: var(--muted); cursor: pointer; display: inline-flex; gap: 6px; align-items: center; text-decoration: none; }
.tab:hover { background: var(--surface-2); }
.tab.active { background: var(--peach); color: #fff; border-color: var(--peach); box-shadow: var(--sh-cta); }
.tab .c { font-size: 11.5px; background: rgba(0,0,0,.06); padding: 2px 8px; border-radius: 8px; font-weight: 700; }
.tab.active .c { background: rgba(255,255,255,.25); color: #fff; }

/* 테이블 — 가독성 개선 */
.table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.table th { text-align: left; padding: 13px 20px; color: var(--muted); font-weight: 700; font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.table td { padding: 15px 20px; border-bottom: 1px solid var(--border); color: var(--text); }
.table tr:last-child td { border: 0; }
.table tr:hover td { background: var(--surface-2); }
.table tr.row-link { cursor: pointer; }
.table tr.row-link:hover td { background: #fff1e3; }
.table .muted { color: var(--muted); font-size: 13.5px; }
.table .name { font-weight: 700; color: var(--text); }

/* 필터 바 — 한 줄 레이아웃 (좁을 때만 가로 스크롤) */
.filter-bar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
.filter-bar input, .filter-bar select { padding: 11px 14px; font-size: 14.5px; background: var(--surface); flex-shrink: 0; }
.filter-bar input[type="text"], .filter-bar input[type="search"] { flex: 1 1 220px; min-width: 180px; }
.filter-bar input[type="date"] { min-width: 150px; }
.filter-bar select { min-width: 130px; max-width: 200px; }
.filter-bar .btn { flex-shrink: 0; white-space: nowrap; }
@media (max-width: 700px) { .filter-bar { flex-wrap: wrap; overflow-x: visible; } }

/* 폼 */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text); }
.field label .req { color: var(--berry); margin-left: 2px; }
.field .hint { font-size: 11.5px; color: var(--muted); }
.field.full { grid-column: 1 / -1; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
@media (max-width: 900px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
.kpi { background: var(--surface); border-radius: var(--r-lg); padding: 20px 22px; border: 1px solid var(--border); }
.kpi .ico { width: 44px; height: 44px; border-radius: var(--r-md); display: flex; align-items: center; justify-content: center; font-size: 22px; margin-bottom: 14px; }
.kpi.peach .ico { background: var(--cream); color: var(--peach-2); }
.kpi.sage  .ico { background: #f1f8e9; color: var(--sage-2); }
.kpi.lilac .ico { background: #ede7f6; color: var(--lilac); }
.kpi.berry .ico { background: #ffebee; color: var(--berry); }
.kpi .lbl { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.kpi .val { font-size: 28px; font-weight: 800; letter-spacing: -0.03em; }
.kpi .val small { font-size: 14px; color: var(--muted); font-weight: 500; margin-left: 4px; }
.kpi .delta { font-size: 12px; margin-top: 6px; font-weight: 600; color: var(--sage-2); }
.kpi .delta.warn { color: var(--peach-2); }
.kpi .delta.danger { color: var(--berry); }

/* 차트 */
.chart { height: 140px; display: flex; align-items: flex-end; gap: 10px; padding: 4px 0 22px; position: relative; }
.chart .bar { flex: 1; position: relative; display: flex; flex-direction: column; justify-content: flex-end; }
.chart .bar .fill { background: linear-gradient(180deg, #ffab91, var(--peach-2)); border-radius: var(--r-sm) var(--r-sm) 4px 4px; min-height: 8px; transition: height .3s; }
.chart .bar .lbl { position: absolute; bottom: -20px; left: 50%; transform: translateX(-50%); font-size: 11.5px; color: var(--muted); font-weight: 500; }
.chart .bar .v { position: absolute; top: -20px; left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--peach-2); font-weight: 700; }

/* 파이프라인 */
.stages { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 22px; }
.stage { padding: 16px 12px; border-radius: var(--r-md); text-align: center; background: var(--surface-2); }
.stage.a { background: #e8f5e9; } .stage.a .n { color: var(--sage-2); }
.stage.b { background: #e3f2fd; } .stage.b .n { color: var(--sky); }
.stage.c { background: var(--cream); } .stage.c .n { color: var(--peach-2); }
.stage.d { background: #ffebee; } .stage.d .n { color: var(--berry); }
.stage .n { font-size: 26px; font-weight: 800; line-height: 1; }
.stage .l { font-size: 11.5px; color: var(--muted); margin-top: 6px; font-weight: 600; }

/* 프로필 아바타 */
.pfp { width: 40px; height: 40px; border-radius: 50%; background: linear-gradient(135deg, #fde68a, #f97316); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px; flex: none; }
.pfp.b { background: linear-gradient(135deg, #bae6fd, #0ea5e9); }
.pfp.c { background: linear-gradient(135deg, #fbcfe8, #ec4899); }
.pfp.d { background: linear-gradient(135deg, #bbf7d0, #16a34a); }
.pfp.e { background: linear-gradient(135deg, #ddd6fe, #7c3aed); }

/* 토스트 */
.toast-host { position: fixed; right: 20px; bottom: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--text); color: #fff; padding: 12px 18px; border-radius: var(--r-md); font-size: 13.5px; font-weight: 500; box-shadow: 0 8px 20px rgba(0,0,0,.15); animation: toast-in .25s; max-width: 320px; }
.toast.ok { background: var(--sage-2); }
.toast.warn { background: var(--peach-2); }
.toast.err { background: var(--berry); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* 모달 */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 9998; animation: fade-in .2s; }
@keyframes fade-in { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: var(--r-xl); padding: 28px 32px; max-width: 500px; width: calc(100% - 32px); box-shadow: 0 12px 40px rgba(0,0,0,.2); max-height: 92vh; overflow-y: auto; }
.modal h3 { margin-bottom: 10px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
@media (max-width: 700px) {
  .modal { padding: 18px 16px; max-width: calc(100vw - 16px) !important; max-height: 95vh; }
  .modal .actions .btn { flex: 1; justify-content: center; }
  .modal .form-grid { grid-template-columns: 1fr !important; gap: 10px !important; }
}

/* 모바일 최적화 — 테이블 → 카드 / 탭/버튼 터치 친화 */
@media (max-width: 700px) {
  /* 패널 헤더 컴팩트 */
  .panel { overflow-x: visible; }
  .panel-h { padding: 13px 16px; flex-wrap: wrap; gap: 8px; }
  .panel-h h3 { font-size: 15px; }
  .panel-b { padding: 12px 14px; }
  .panel-b.nopad { padding: 0; }

  /* 탭은 가로 스크롤 */
  .tabs { overflow-x: auto; flex-wrap: nowrap !important; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
  .tabs .tab { white-space: nowrap; flex-shrink: 0; }

  /* 버튼 터치 친화 */
  .btn { padding: 11px 14px; font-size: 14px; min-height: 40px; }
  .btn.sm { min-height: 32px; padding: 7px 11px; }

  /* 카드/Hero 패딩 축소 */
  .card { padding: 16px; }
  .hero { padding: 16px 18px; margin-bottom: 14px; }
  .hero h1 { font-size: 18px; }
  .hero p { font-size: 12.5px; line-height: 1.55; }
  .hero::after { font-size: 80px; right: -5px; bottom: -5px; }
  .hero .actions { gap: 6px; margin-top: 12px; }
  .hero .actions .btn { padding: 8px 12px; font-size: 13px; min-height: 36px; }

  /* KPI: 가로 컴팩트 — 아이콘 좌측 + 텍스트 우측 */
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 14px; }
  .kpi {
    display: grid; grid-template-columns: auto 1fr; gap: 10px;
    padding: 12px 14px; align-items: center;
  }
  .kpi .ico { width: 36px; height: 36px; font-size: 17px; margin-bottom: 0; grid-row: span 2; }
  .kpi .lbl { font-size: 11px; margin-bottom: 0; }
  .kpi .val { font-size: 18px; font-weight: 800; }
  .kpi .val small { font-size: 11px; }
  .kpi .delta { display: none; }

  /* 그리드 강제 1열 */
  .grid { grid-template-columns: 1fr !important; }

  /* ─────────────────────────────────────────
     테이블 → 카드 변환 (.table 사용 페이지 전반)
     첫 셀 = 제목 / 마지막 .text-right 셀 = 액션
     ───────────────────────────────────────── */
  .table { background: transparent; font-size: 13px; }
  .table thead { display: none; }
  .table tbody, .table tr { display: block; width: 100%; }
  .table tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    margin-bottom: 8px;
    padding: 12px 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,.04);
  }
  .table tr:hover td,
  .table tr.row-link:hover td { background: transparent !important; }
  .table tr td {
    display: block;
    border: 0 !important;
    padding: 3px 0 !important;
    font-size: 13px;
    color: var(--text);
  }
  /* 첫 셀이 보통 컨텐츠(.muted 가 아니면) → 제목 스타일 */
  .table tr td:first-child:not(.muted) {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 6px;
    padding-bottom: 8px !important;
    border-bottom: 1px solid var(--border) !important;
  }
  /* 첫 셀이 .muted (mono 코드 등 보조 정보) → 작은 태그처럼 */
  .table tr td:first-child.muted {
    font-size: 10.5px;
    font-family: ui-monospace, monospace;
    color: var(--muted);
    background: var(--surface-2);
    display: inline-block;
    padding: 2px 8px !important;
    border-radius: 999px;
    margin-bottom: 6px;
  }
  /* 그 다음 셀이 진짜 제목 */
  .table tr td:first-child.muted + td {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 6px;
    padding-bottom: 8px !important;
    border-bottom: 1px solid var(--border) !important;
  }
  .table tr td.text-right {
    margin-top: 8px;
    padding-top: 8px !important;
    border-top: 1px solid var(--border) !important;
    text-align: left;
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
    align-items: center;
  }
  .table tr td.text-right .btn {
    flex: 1 1 0;
    min-width: 0;       /* .btn.sm 의 min-width:60px 를 모바일에서 풀어 한 줄에 맞춤 */
    justify-content: center;
    padding-left: 8px;  /* 모바일에서 버튼 좌우 패딩 축소로 공간 절약 */
    padding-right: 8px;
    white-space: nowrap;
  }
  .table tr td .pill { margin-right: 4px; }
  .table tr td.muted { color: var(--muted); font-size: 12.5px; }
  .table tr td br { display: none; }

  /* 빈 상태 행은 카드 처리 안 함 */
  .table tr td[colspan] { font-size: 13px; padding: 24px 8px !important; text-align: center; }

  /* data-mlabel 속성으로 모바일 라벨 노출 */
  .table tr td[data-mlabel]::before {
    content: attr(data-mlabel) ' · ';
    color: var(--muted);
    font-size: 11.5px;
    font-weight: 600;
    margin-right: 4px;
  }

  /* ─────────────────────────────────────────
     캘린더(.cal-table) — 7열은 유지하되 컴팩트
     ───────────────────────────────────────── */
  .cal-table { font-size: 11px; }
  .cal-table thead th { padding: 6px 2px !important; font-size: 12px; }
  .cal-table tbody td { height: auto !important; min-height: 90px; padding: 4px 3px !important; }
  .cal-table .cal-bk { font-size: 9.5px !important; padding: 2px 3px !important; }

  /* 픽업 모달의 등록된 카드 모바일 */
  #pmBookedBox { max-height: 130px !important; }

  /* 필터바 한 줄 위트랩 */
  .filter-bar input[type="text"], .filter-bar input[type="search"] { min-width: 0 !important; }
  .filter-bar .btn { min-width: 60px; }
  /* .hide-mob — 모바일에서만 숨김 */
  .hide-mob { display: none !important; }
}

/* 정보 그리드 — 라벨/값 페어 (상세 페이지 기본 정보) */
.info-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px 22px; }
.info-row { display: flex; flex-direction: column; gap: 4px; }
.info-row.full { grid-column: 1 / -1; }
.info-row .lbl { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.info-row .val { font-size: 14.5px; font-weight: 600; color: var(--text); line-height: 1.5; word-break: break-word; }
@media (max-width: 700px) {
  .info-grid { grid-template-columns: 1fr; gap: 0; }
  .info-row {
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
  }
  .info-row:last-child { border-bottom: 0; padding-bottom: 0; }
  .info-row:first-child { padding-top: 0; }
  .info-row .lbl { font-size: 12px; min-width: 92px; flex-shrink: 0; text-transform: none; letter-spacing: 0; padding-top: 2px; }
  .info-row .val { font-size: 14px; text-align: right; }
  .info-row.full { flex-direction: column; gap: 4px; }
  .info-row.full .lbl { padding-top: 0; }
  .info-row.full .val { text-align: left; }
}

/* 페이지네이션 */
.pager { display: flex; gap: 4px; justify-content: center; padding: 16px; }
.pager a, .pager span { padding: 6px 12px; border-radius: var(--r-sm); font-size: 13px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); }
.pager a:hover { background: var(--surface-2); }
.pager .active { background: var(--peach); color: #fff; border-color: var(--peach); font-weight: 700; }
.pager .disabled { opacity: .4; pointer-events: none; }

/* 플래시 */
.flash { padding: 12px 18px; border-radius: var(--r-md); margin-bottom: 16px; font-size: 13.5px; font-weight: 500; }
.flash.ok { background: #e8f5e9; color: var(--sage-2); border: 1px solid #c8e6c9; }
.flash.warn { background: var(--cream); color: var(--peach-2); border: 1px solid #ffe0b2; }
.flash.err { background: #ffebee; color: var(--berry); border: 1px solid #ffcdd2; }
