/* 아크시스템즈 관리자 — 반응형 공통 스타일 (토스 톤)
   모바일 우선: 하단 탭바 / 데스크탑(>=900px): 좌측 사이드바 */

:root {
  --primary: #3182f6;
  --primary-dark: #1b64da;
  --primary-bg: #e8f3ff;
  --bg: #ffffff;
  --bg-soft: #f2f4f6;
  --bg-muted: #f9fafb;
  --text: #191f28;
  --text-2: #4e5968;
  --text-3: #8b95a1;
  /* 별칭 — 여러 화면이 아래 이름으로 쓰고 있었는데 정의가 없어 색이 안 먹었다.
     (--text-1: merchants/add·edit, orgs/*, notices, login  /  --muted: legacy/*, system/*)
     새 코드는 --text / --text-3 을 쓸 것. 이 둘은 기존 화면 호환용이다. */
  --text-1: #191f28;
  --muted:  #8b95a1;
  --divider: #e5e8eb;
  --border: #d1d6db;
  --success: #15803d;
  --success-bg: #e7f7ee;
  --warning: #d97706;
  --warning-bg: #fff4e5;
  --danger: #e02020;
  --danger-bg: #fdeaea;
  --purple: #7c3aed;
  --radius: 14px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
  --nav-w: 232px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
    "Malgun Gothic", sans-serif;
  background: var(--bg-soft);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 15px; }

/* ─── 레이아웃 셸 ─────────────────────────────── */
.app {
  display: flex;
  min-height: 100vh;
}

/* 사이드바 (데스크탑) */
.sidebar {
  display: none;
  width: var(--nav-w);
  background: var(--bg);
  border-right: 1px solid var(--divider);
  position: fixed;
  top: 0; bottom: 0; left: 0;
  padding: 22px 14px;
  flex-direction: column;
  gap: 4px;
  z-index: 20;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px 20px;
}
.sidebar .brand .logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 18px;
}
.sidebar .brand b { font-size: 16px; font-weight: 800; }
.sidebar .brand span { font-size: 11px; color: var(--text-3); display: block; }

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 600; font-size: 14.5px;
}
.nav-item .ic { font-size: 18px; width: 22px; text-align: center; }
.nav-item:hover { background: var(--bg-soft); }
.nav-item.active { background: var(--primary-bg); color: var(--primary-dark); }
.sidebar .spacer { flex: 1; }
.sidebar .logout {
  color: var(--text-3); font-size: 13px; padding: 12px 14px;
}

/* 본문 */
.main {
  flex: 1;
  min-width: 0;
  padding-bottom: 84px; /* 모바일 탭바 공간 */
}

/* 상단바 */
.topbar {
  position: sticky; top: 0; z-index: 15;
  background: var(--bg);
  border-bottom: 1px solid var(--divider);
  height: 56px;
  display: flex; align-items: center;
  padding: 0 16px; gap: 10px;
}
.topbar .title { font-size: 17px; font-weight: 800; }
.topbar .sp { flex: 1; }
.topbar .me {
  font-size: 12px; color: var(--text-3);
  display: flex; align-items: center; gap: 6px;
}
.topbar .me .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }

.content { padding: 16px; max-width: 1650px; margin: 0 auto; }

/* 하단 탭바 (모바일) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--bg);
  border-top: 1px solid var(--divider);
  display: flex;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbar a {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 0;
  color: var(--text-3); font-size: 11px; font-weight: 600;
}
.tabbar a .ic { font-size: 20px; }
.tabbar a.active { color: var(--primary); }

/* ─── 공통 컴포넌트 ───────────────────────────── */
.card {
  background: var(--bg);
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  padding: 18px;
}
.card + .card { margin-top: 12px; }
.card-title { font-size: 15px; font-weight: 800; margin-bottom: 14px; }

.grid { display: grid; gap: 12px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-5 { grid-template-columns: repeat(2, 1fr); }

/* 통계 카드 */
.stat {
  background: var(--bg);
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  padding: 16px;
}
.stat .label { font-size: 12px; color: var(--text-3); font-weight: 600; }
.stat .value { font-size: 22px; font-weight: 800; margin-top: 6px; letter-spacing: -0.5px; }
.stat .sub { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.stat .value.blue { color: var(--primary); }
.stat .value.green { color: var(--success); }
.stat .value.purple { color: var(--purple); }

/* 버튼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 18px; border-radius: var(--radius-sm);
  font-weight: 700; font-size: 14.5px; border: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: var(--bg-soft); color: var(--text-2); }
.btn-line { background: var(--bg); border: 1.5px solid var(--border); color: var(--text-2); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 13px; }
/* 표 안의 버튼은 글자를 접지 않는다.
   칸이 좁으면 '품목' 이 '품 / 목' 으로 세로로 접혀 버린다(shop/orders.php 에서 실제로 났다).
   .btn 전체에 걸지 않는 이유: 허브 카드처럼 설명문이 두 줄로 들어가는 버튼이 있어
   nowrap 이 자식까지 상속되면 그쪽이 넘친다. 표 안으로만 한정한다. */
.table .btn { white-space: nowrap; }
.btn-danger { background: var(--danger-bg); color: var(--danger); }

/* 폼 */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px;
  background: var(--bg-soft);
  border: 1px solid var(--divider); border-radius: var(--radius-sm);
  color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); background: #fff;
}

/* 배지 */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700;
}
.badge.green { background: var(--success-bg); color: var(--success); }
.badge.warn { background: var(--warning-bg); color: var(--warning); }
.badge.red { background: var(--danger-bg); color: var(--danger); }
.badge.blue { background: var(--primary-bg); color: var(--primary-dark); }
.badge.gray { background: var(--bg-soft); color: var(--text-3); }

/* 리스트 행 */
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 0; border-bottom: 1px solid var(--divider);
}
.row:last-child { border-bottom: none; }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 700; font-size: 14.5px; }
.row .s { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }
.row .amt { font-weight: 800; font-size: 15px; white-space: nowrap; }

/* 반응형 전환 — PC=표 / 모바일=카드 */
.pc-only { display: none; }
.mobile-only { display: block; }
@media (min-width: 900px) {
  .pc-only { display: block; }
  .mobile-only { display: none; }
}

/* 필터 바 */
.filters {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-bottom: 14px;
}
/* .seg 는 .filters 밖(예: .section-head 오른쪽)에서도 쓰므로 단독 선택자도 같이 둔다.
   예전엔 .filters .seg 만 있어서 필터바 밖에 놓으면 스타일이 통째로 빠졌다. */
.seg, .filters .seg {
  display: inline-flex; align-items: center; background: var(--bg-soft);
  border-radius: var(--radius-sm); padding: 3px; gap: 2px;
}
.seg a, .seg span, .filters .seg a, .filters .seg span {
  display: inline-flex; align-items: center;
  padding: 7px 12px; border-radius: 6px; font-size: 13px; font-weight: 600;
  color: var(--text-2);
}
.seg a.on, .seg span.on,
.filters .seg a.on, .filters .seg span.on { background: var(--bg); color: var(--primary); box-shadow: var(--shadow); }
/* number·datetime-local 도 포함 — 빠져 있어서 그 입력칸만 브라우저 기본 모양으로 떴다 */
.filters input[type=text], .filters input[type=date], .filters input[type=number],
.filters input[type=datetime-local], .filters select {
  padding: 9px 11px; border: 1px solid var(--divider);
  border-radius: var(--radius-sm); background: var(--bg-soft); font-size: 13.5px;
  color: var(--text);
}
.filters input[type=text]:focus, .filters input[type=date]:focus, .filters input[type=number]:focus,
.filters input[type=datetime-local]:focus, .filters select:focus {
  outline: none; border-color: var(--primary); background: #fff;
}
.filters .grow { flex: 1; min-width: 120px; }

/* 검색 가능한 셀렉트 (select[data-searchable] → 검색 콤보박스) */
.ssel { position: relative; }
.ssel-input {
  width: 100%; height: 40px; box-sizing: border-box;
  border: 1px solid var(--divider); border-radius: var(--radius-sm);
  padding: 0 12px; font-size: 13.5px; background: var(--bg-soft); outline: none;
}
.ssel-input:focus { border-color: var(--primary); background: #fff; }
.ssel-list {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 1200;
  max-height: 280px; overflow: auto; background: #fff;
  border: 1px solid var(--divider); border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.16);
}
.ssel-item { padding: 9px 12px; cursor: pointer; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ssel-item:hover { background: #f2f6ff; }
.ssel-empty { padding: 12px; color: #8b95a1; font-size: 12.5px; text-align: center; }

/* 페이지네이션 */
.pager { display: flex; justify-content: center; align-items: center; gap: 4px; margin-top: 18px; flex-wrap: wrap; }
.pager a, .pager span {
  min-width: 36px; height: 36px; padding: 0 10px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 600;
  color: var(--text-2); background: var(--bg); border: 1px solid var(--divider);
}
.pager a:hover { background: var(--bg-soft); }
.pager .cur { background: var(--primary); color: #fff; border-color: var(--primary); }
.pager .gap { border: none; background: none; }

/* 테이블 (데스크탑) */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 10px; text-align: left; border-bottom: 1px solid var(--divider); font-size: 13.5px; }
.table tbody tr:hover { background: var(--bg-muted); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table th { color: var(--text-3); font-weight: 700; font-size: 12px; }

/* 섹션 헤더 */
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 4px 2px 12px;
}
.section-head h2 { font-size: 15px; font-weight: 800; }

.empty { text-align: center; color: var(--text-3); font-size: 13px; padding: 40px 0; }

/* ─── 로그인 ─────────────────────────────────── */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: var(--bg-soft);
}
.login-box {
  width: 100%; max-width: 380px;
  background: var(--bg); border-radius: var(--radius-lg);
  padding: 32px 24px; box-shadow: var(--shadow-md);
}
.login-box .logo {
  width: 96px; height: 96px; border-radius: 20px; margin: 0 auto 18px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 42px;
}
.login-box h1 { text-align: center; font-size: 20px; font-weight: 800; }
.login-box .desc { text-align: center; color: var(--text-3); font-size: 13px; margin: 6px 0 24px; }
.login-box .err {
  background: var(--danger-bg); color: var(--danger);
  font-size: 13px; padding: 10px 12px; border-radius: var(--radius-sm); margin-bottom: 14px;
}

/* ─── 반응형 분기 ─────────────────────────────── */
@media (min-width: 900px) {
  .sidebar { display: flex; }
  .main { margin-left: var(--nav-w); padding-bottom: 0; }
  .tabbar { display: none; }
  .grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
  .grid.cols-5 { grid-template-columns: repeat(5, 1fr); }
  .topbar { padding: 0 24px; }
  .content { padding: 24px; }
}

/* ─── 사이드바 접기/펼치기 (데스크탑) ───────────── */
.sidebar, .main { transition: transform .2s ease, margin-left .2s ease; }
.content { transition: max-width .2s ease; }
.sb-toggle { display: none; }
@media (min-width: 900px) {
  .sb-toggle {
    display: flex; align-items: center; justify-content: center;
    position: fixed; top: 50%; transform: translateY(-50%);
    left: calc(var(--nav-w) - 13px); z-index: 30;
    width: 26px; height: 26px; border-radius: 50%;
    background: var(--bg); border: 1px solid var(--divider);
    box-shadow: 0 1px 4px rgba(0,0,0,.12);
    color: var(--text-2); font-size: 15px; line-height: 1; cursor: pointer;
    transition: left .2s ease;
  }
  .sb-toggle:hover { background: var(--bg-soft); }
  .app.sb-collapsed .sidebar { transform: translateX(-100%); }
  .app.sb-collapsed .main { margin-left: 0; }
  .app.sb-collapsed .content { max-width: calc(1650px + var(--nav-w)); }
  .app.sb-collapsed .sb-toggle { left: 6px; }
}


/* ══════════════════════════════════════════════════════════════════
   모바일 보정 (≤ 899px)
   ──────────────────────────────────────────────────────────────────
   이 프로젝트는 원래 모바일 우선(사이드바 숨김 → 하단 탭바)으로 짜여 있다.
   문제는 '표' 였다. .table 을 쓰는 화면이 51개인데 그중 26개만
   .pc-only/.mobile-only 로 카드 전환을 하고, 나머지는 표가 화면 밖으로
   삐져나가 가로 스크롤이 페이지 전체에 걸렸다.
   여기서는 화면 파일을 하나하나 고치지 않고 CSS 만으로 공통 보정한다.
   ══════════════════════════════════════════════════════════════════ */
@media (max-width: 899px) {

  /* ── 표: 래퍼가 없어도 '표 안에서만' 가로 스크롤 ──────────────────
     table 에 display:block 을 주면 표 자체가 스크롤 박스가 된다.
     (.tw 같은 래퍼가 이미 있는 화면은 그 래퍼가 먼저 잡으므로 영향 없음) */
  .card table.table,
  .card table:not(.kv) {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  /* 스크롤이 가능하다는 걸 보이게 — 얇은 스크롤바 */
  .card table.table::-webkit-scrollbar { height: 6px; }
  .card table.table::-webkit-scrollbar-thumb { background: var(--divider); border-radius: 3px; }

  /* 표 셀 여백을 줄여 한 화면에 더 담는다 */
  .table th, .table td { padding: 10px 8px; font-size: 12.5px; }
  .table th { font-size: 11.5px; }

  /* 표 안에 들어가는 폼(해제·저장 버튼 등)이 세로로 터지지 않게 */
  .table form { display: inline-flex; gap: 4px; align-items: center; }
  .table input[type=text], .table input[type=number] { min-width: 90px; }

  /* ── 통계 카드: 3열 이상은 2열로, 아주 좁으면 1열 ───────────────── */
  .grid.cols-3 { grid-template-columns: repeat(2, 1fr); }
  .stat { padding: 12px; }
  .stat .value { font-size: 18px; }

  /* ── 섹션 헤더: 제목과 우측 요소가 겹치지 않게 ──────────────────── */
  .section-head { flex-wrap: wrap; gap: 8px; }
  .section-head h2 { font-size: 14px; }

  /* ── 필터 바: 입력칸이 지나치게 좁아지지 않게 ───────────────────── */
  .filters { gap: 6px; }
  .filters input[type=text], .filters input[type=date],
  .filters input[type=number], .filters input[type=month],
  .filters input[type=datetime-local], .filters select {
    min-width: 0; flex: 1 1 130px; padding: 8px 10px; font-size: 13px;
  }
  .filters .grow { flex: 1 1 100%; }          /* 검색어 칸은 한 줄 통째로 */
  .filters .btn { flex: 0 0 auto; }
  .filters .seg { overflow-x: auto; max-width: 100%; }
  .filters .seg a, .filters .seg span { padding: 6px 10px; font-size: 12.5px; white-space: nowrap; }

  /* ── 카드/여백 ─────────────────────────────────────────────────── */
  .content { padding: 12px; }
  .card { padding: 14px; }
  .card-title { font-size: 14px; }

  /* ── 긴 코드·계좌·URL 이 화면을 밀어내지 않게 ───────────────────── */
  .card { overflow-wrap: anywhere; }

  /* ── 버튼: 터치 영역 확보 + 줄바꿈 ─────────────────────────────── */
  .btn { min-height: 38px; }
  .btn-sm { min-height: 32px; }

  /* ── 폼 필드: 라벨+입력 세로 배치 ───────────────────────────────── */
  .field input, .field select, .field textarea { font-size: 15px; }  /* iOS 확대 방지(16px 미만이면 확대됨→15px+ 로) */

  /* ── 페이지네이션 ──────────────────────────────────────────────── */
  .pager a, .pager span { min-width: 32px; padding: 6px 8px; font-size: 12.5px; }
}

/* 아주 좁은 화면(≤ 480px) — 통계는 1열이 낫다 */
@media (max-width: 480px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4, .grid.cols-5 { grid-template-columns: 1fr; }
  .stat .value { font-size: 20px; }
}
