/* ─────────────────────────────────────────────────────────────
   어드민 — 데스크톱 우선, 데이터 밀도 높게
   ───────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg:        #f4f5f7;
  --surface:   #ffffff;
  --border:    #e5e7eb;
  --text:      #1f2328;
  --muted:     #6e7681;
  --primary:   #ff5a1f;
  --primary-d: #e64500;
  --info:      #1f6feb;
  --success:   #1f7a1f;
  --warn:      #b58105;
  --danger:    #d33a2c;
  --shadow:    0 1px 2px rgba(0,0,0,.04), 0 4px 12px rgba(0,0,0,.06);
  --radius:    8px;

  /* 상태 색 */
  --st-pending:   #6e7681;
  --st-paid:      #1f6feb;
  --st-sending:   #8957e5;
  --st-sent:      #1f7a1f;
  --st-partial:   #d48806;
  --st-fail:      #d33a2c;
  --st-hold:      #b58105;
  --st-cancelled: #9ca3af;
  --st-expired:   #adb5bd;

  /* 입금 상태 색 */
  --dep-new:       #6e7681;
  --dep-matched:   #1f7a1f;
  --dep-unmatched: #d33a2c;
  --dep-duplicate: #b58105;
}

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
               "Malgun Gothic", "맑은 고딕", "Noto Sans KR", sans-serif;
  font-size: 13.5px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--muted); }
.small { font-size: 12px; }
.num   { text-align: right; font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ─── 로그인 ─────────────────────────────────────────── */
body.login-page {
  min-height: 100vh;
  display: grid; place-items: center;
  background: linear-gradient(180deg, #f4f5f7 0%, #e9ebef 100%);
}
.login-card {
  background: #fff;
  width: min(380px, calc(100vw - 32px));
  padding: 28px 24px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card h1 { margin: 0 0 4px; font-size: 18px; }
.login-card p  { margin: 0 0 18px; }
.btn-google {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 10px; width: 100%;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px; font-weight: 600;
  cursor: pointer;
}
.btn-google:hover { background: #f7f7f8; }
.btn-google .g-icon {
  display: inline-grid; place-items: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #4285f4; color: #fff; font-weight: 800;
}
.footnote { margin-top: 18px; font-size: 11px; }

/* ─── 알림 ─────────────────────────────────────────── */
.alert {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  text-align: left;
}
.alert-error { background: #fdecea; color: var(--danger); border: 1px solid #f5c6c2; }
.alert-warn  { background: #fff8e1; color: var(--warn);   border: 1px solid #ffe69c; }
.alert-info  { background: #e7f3ff; color: #0a558c;       border: 1px solid #b3d7f5; }

/* ─── 대시보드 레이아웃 ────────────────────────────── */
body.dashboard-page {
  min-height: 100vh;
  display: flex; flex-direction: column;
}

/* 상단 바 */
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 16px;
  align-items: center;
  position: sticky; top: 0; z-index: 20;
}
.topbar-brand strong { font-size: 14px; }
.topbar-stats {
  display: flex; gap: 18px;
  flex-wrap: wrap;
}
.stat {
  text-align: right;
  min-width: 84px;
}
.stat-label { font-size: 11px; color: var(--muted); }
.stat-value { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.warn .stat-value { color: var(--danger); }

/* 잔액 4단계 색상 (L-1) */
.stat.bal-ok     .stat-value { color: var(--success); }
.stat.bal-warn   .stat-value { color: #ca8a04; }
.stat.bal-alert  .stat-value { color: #ea580c; }
.stat.bal-danger .stat-value { color: var(--danger); font-weight: 800; }

.topbar-actions {
  display: flex; align-items: center; gap: 12px;
}

/* 워커 인디케이터 */
.worker-indicator {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: #fff;
  cursor: default;
  white-space: nowrap;
}
.worker-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
  display: inline-block;
}
.worker-dot.green  { background: #1f7a1f; box-shadow: 0 0 0 3px rgba(31,122,31,.18); }
.worker-dot.yellow { background: #b58105; box-shadow: 0 0 0 3px rgba(181,129,5,.18); }
.worker-dot.red    { background: #d33a2c; box-shadow: 0 0 0 3px rgba(211,58,44,.18); }
.worker-label { font-size: 12px; color: var(--text); font-variant-numeric: tabular-nums; }

/* 토글 스위치 */
.toggle {
  display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer;
  user-select: none;
}
.toggle input { display: none; }
.toggle-track {
  width: 36px; height: 20px;
  background: #d0d3d8;
  border-radius: 99px;
  position: relative;
  transition: background .15s;
}
.toggle-track::after {
  content: ""; position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
  transition: transform .15s;
}
.toggle input:checked + .toggle-track {
  background: var(--primary);
}
.toggle input:checked + .toggle-track::after {
  transform: translateX(16px);
}
.toggle-label { font-size: 12px; color: var(--muted); }

/* ─── 탭 ────────────────────────────────────────────── */
.tabs {
  display: flex;
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 0 8px;
  position: sticky; top: 49px; z-index: 19;
}
.tab {
  padding: 10px 14px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 13px; font-weight: 600;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--text);
  border-bottom-color: var(--primary);
}

/* ─── 컨텐츠 ────────────────────────────────────────── */
.content {
  padding: 16px;
  flex: 1;
}
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* 툴바 */
.pane-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
  gap: 12px;
}
.filter-group {
  display: flex; gap: 8px; align-items: center;
}
.filter-group select,
.filter-group input {
  padding: 6px 8px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}
.filter-group input { min-width: 200px; }

/* ─── 표 ────────────────────────────────────────────── */
.table-wrap {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th,
.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
.data-table th {
  background: #fafbfc;
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  position: sticky; top: 0;
}
.data-table tbody tr:hover {
  background: #fafbfc;
  cursor: pointer;
}
.data-table tbody tr:last-child td { border-bottom: none; }

.empty {
  padding: 32px;
  text-align: center;
  color: var(--muted);
  background: #fff;
}

/* 상태 pill */
.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 600;
  color: #fff;
  background: #888;
  white-space: nowrap;
}
.pill-pending   { background: var(--st-pending); }
.pill-paid      { background: var(--st-paid); }
.pill-sending   { background: var(--st-sending); }
.pill-sent         { background: var(--st-sent); }
.pill-sent_partial { background: var(--st-partial); }
.pill-fail         { background: var(--st-fail); }
.pill-hold      { background: var(--st-hold); }
.pill-cancelled { background: var(--st-cancelled); }
.pill-expired   { background: var(--st-expired); }

/* row 좌측 액센트 */
.row.status-pending   td:first-child { box-shadow: inset 3px 0 0 var(--st-pending); }
.row.status-paid      td:first-child { box-shadow: inset 3px 0 0 var(--st-paid); }
.row.status-sending   td:first-child { box-shadow: inset 3px 0 0 var(--st-sending); }
.row.status-sent         td:first-child { box-shadow: inset 3px 0 0 var(--st-sent); }
.row.status-sent_partial td:first-child { box-shadow: inset 3px 0 0 var(--st-partial); }
.row.status-fail         td:first-child { box-shadow: inset 3px 0 0 var(--st-fail); }
.row.status-hold      td:first-child { box-shadow: inset 3px 0 0 var(--st-hold); }
.row.status-cancelled td:first-child { box-shadow: inset 3px 0 0 var(--st-cancelled); }
.row.status-expired   td:first-child { box-shadow: inset 3px 0 0 var(--st-expired); }

/* 입금 상태 pill */
.dep-pill-new       { background: var(--dep-new); }
.dep-pill-matched   { background: var(--dep-matched); }
.dep-pill-unmatched { background: var(--dep-unmatched); }
.dep-pill-duplicate { background: var(--dep-duplicate); }
.dep-pill-refunded  { background: #1f6feb; }
.dep-pill-ignored   { background: #9ca3af; }

.row.dep-unmatched td:first-child { box-shadow: inset 3px 0 0 var(--dep-unmatched); }
.row.dep-duplicate td:first-child { box-shadow: inset 3px 0 0 var(--dep-duplicate); }
.row.dep-needs-action td:first-child { box-shadow: inset 4px 0 0 var(--danger); }
.row.dep-needs-action  { background: rgba(211, 58, 44, .04); }

/* 처리 필요 빨간 뱃지 */
.badge-need {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  background: var(--danger);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  border-radius: 99px;
  vertical-align: middle;
}

/* ─── 액션 버튼 ─────────────────────────────────────── */
.btn-row {
  display: inline-flex; gap: 4px; flex-wrap: wrap;
}
.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover { background: #f7f7f8; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-sm { padding: 4px 8px; font-size: 12px; }
.btn-primary {
  background: var(--primary); color: #fff; border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-d); border-color: var(--primary-d); }
.btn-warn {
  background: var(--warn); color: #fff; border-color: var(--warn);
}
.btn-warn:hover { filter: brightness(1.05); }
.btn-ghost {
  background: transparent; color: var(--muted);
}
.btn-ghost:hover { background: #f0f0f2; color: var(--text); }

/* ─── 모달 ─────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  display: grid; place-items: center;
  z-index: 100;
  padding: 16px;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: #fff;
  border-radius: 10px;
  width: min(520px, 100%);
  max-height: 88vh;
  overflow: auto;
  box-shadow: 0 20px 50px rgba(0,0,0,.2);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 15px; }
.modal-close {
  background: transparent; border: none; cursor: pointer;
  font-size: 22px; line-height: 1; color: var(--muted);
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 16px 18px; }

.detail { display: flex; flex-direction: column; gap: 4px; }
.detail-row {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.detail-row:last-child { border-bottom: none; }
.detail-row.stack { grid-template-columns: 1fr; gap: 6px; }
.detail-k { color: var(--muted); font-size: 12px; }
.detail-v { font-size: 13.5px; word-break: break-all; }
.memo-editor {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  font: inherit;
  resize: vertical;
}

/* ─── 타임라인 ─────────────────────────────────────── */
.timeline {
  margin: 8px 0 4px;
  padding: 12px;
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex; flex-direction: column; gap: 4px;
}
.tl-title {
  font-size: 12px; color: var(--muted); font-weight: 700;
  margin-bottom: 4px;
}
.tl-row {
  display: grid;
  grid-template-columns: 24px 80px 1fr auto;
  gap: 6px;
  font-size: 13px;
  align-items: center;
}
.tl-icon  { text-align: center; }
.tl-label { color: var(--muted); }
.tl-time  { font-variant-numeric: tabular-nums; font-weight: 600; }
.tl-delta { color: var(--muted); font-size: 11.5px; }
.tl-divider {
  border-top: 1px dashed var(--border);
  margin: 4px 0;
}
.tl-summary {
  display: flex; justify-content: space-between;
  font-size: 13px;
}

/* ─── send_log ─────────────────────────────────────── */
.send-log {
  margin-top: 8px;
  padding: 12px;
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex; flex-direction: column; gap: 6px;
}
.sl-row {
  display: grid;
  grid-template-columns: 32px 48px 1fr auto;
  gap: 6px;
  font-size: 12.5px;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
.sl-row:last-child { border-bottom: none; }
.sl-no   { color: var(--muted); font-weight: 700; }
.sl-stat { font-weight: 700; }
.sl-ok .sl-stat   { color: var(--success); }
.sl-fail .sl-stat { color: var(--danger);  }
.sl-time { font-variant-numeric: tabular-nums; }
.sl-dur  { color: var(--muted); font-size: 11px; }
.sl-reason {
  grid-column: 1 / -1;
  font-size: 11.5px;
  color: var(--text);
  background: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  border-left: 3px solid var(--danger);
  word-break: break-all;
}
.sl-reason.muted { border-left-color: var(--muted); color: var(--muted); }

/* ─── 통계 ─────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.stat-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.stat-card-label { color: var(--muted); font-size: 12px; }
.stat-card-value { font-size: 22px; font-weight: 800; margin: 4px 0 2px; }

.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card h3 { margin: 0 0 12px; font-size: 13.5px; color: var(--muted); }

.hour-chart {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 4px;
  height: 160px;
  align-items: end;
}
.hour-col {
  display: flex; flex-direction: column; align-items: center;
  height: 100%;
}
.hour-bar {
  width: 100%;
  background: var(--primary);
  border-radius: 3px 3px 0 0;
  min-height: 1px;
}
.hour-label {
  font-size: 10px; color: var(--muted); margin-top: 4px;
}

/* ─── 설정 폼 ───────────────────────────────────────── */
.config-form {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  max-width: 640px;
  display: flex; flex-direction: column; gap: 14px;
}
.config-row {
  display: flex; flex-direction: column; gap: 4px;
}
.config-row.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.config-row.toggles {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  gap: 8px;
}
.config-form label {
  font-size: 12px; color: var(--muted); font-weight: 600;
}
.config-form textarea,
.config-form input[type="text"],
.config-form input[type="tel"],
.config-form input[type="url"],
.config-form input[type="time"],
.config-form input[type="number"] {
  padding: 8px 10px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}
.config-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(255,90,31,.15);
}
.check {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text);
  cursor: pointer;
}
.config-actions {
  display: flex; align-items: center; gap: 12px;
  padding-top: 4px;
}

/* ─── 토스트 ───────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 16px; right: 16px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 200;
  max-width: 320px;
}
.toast {
  padding: 10px 14px;
  border-radius: 6px;
  background: #1f2328;
  color: #fff;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0,0,0,.2);
  transition: opacity .25s, transform .25s;
}
.toast.fade { opacity: 0; transform: translateY(8px); }
.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-warn    { background: var(--warn); }

/* ─── 반응형 — 작은 화면 보정 ─────────────────────── */
@media (max-width: 900px) {
  .topbar {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .filter-group input { min-width: 0; flex: 1; }
}
@media (max-width: 600px) {
  .topbar-stats { gap: 12px; }
  .stat { min-width: 64px; }
  .data-table th, .data-table td { padding: 6px 8px; }
}
