/* 동의했어요 관리자 — 앱과 같은 흑백 톤 */
:root {
  --bg: #ffffff;
  --surface: #f5f7fa;
  --text: #000000;
  --body: #424242;
  --muted: #757575;
  --faint: #9e9e9e;
  --line: #e0e0e0;
  --line-soft: #f0f0f0;
  --ok: #1e9e5a;
  --warn: #c77700;
  --danger: #e53935;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", sans-serif;
  font-size: 14px;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--text);
  background: var(--text);
  color: var(--bg);
  padding: 8px 14px;
  font-weight: 600;
}
button.ghost { background: var(--bg); color: var(--text); border-color: var(--line); }
button.danger { background: var(--bg); color: var(--danger); border-color: var(--danger); }
button:disabled { opacity: .35; cursor: default; }
/* 버튼 모양 링크 (콘솔 바로가기 등) */
a.button {
  display: inline-block; text-decoration: none; border-radius: 8px; padding: 8px 14px; font-weight: 600;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
a.button:hover { border-color: var(--text); }

input, textarea, select {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--text); }

.center { text-align: center; margin-top: 18vh; }
.muted { color: var(--muted); }

/* 로그인·권한 없음 */
.gate { max-width: 360px; margin: 18vh auto 0; text-align: center; }
.gate h1 { font-size: 22px; margin-bottom: 6px; }
.gate p { color: var(--muted); line-height: 1.5; }
.gate .actions { display: flex; gap: 8px; justify-content: center; margin-top: 20px; }
.gate code { background: var(--surface); padding: 2px 6px; border-radius: 4px; font-size: 12px; }

/* 레이아웃: 왼쪽 세로 메뉴 + 오른쪽 본문 */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 200px; flex-shrink: 0;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 0; height: 100vh;
}
.sidebar h1 { font-size: 16px; margin: 0; padding: 20px 18px 16px; }
nav.tabs { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; overflow-y: auto; }
nav.tabs button {
  background: none; color: var(--body); border: none; text-align: left;
  padding: 10px 12px; font-weight: 500;
}
nav.tabs button:hover { background: var(--line-soft); }
nav.tabs button.on { background: var(--text); color: var(--bg); font-weight: 600; }
/* 메뉴 오른쪽 끝 숫자: 처리할 일 건수 */
nav.tabs button { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tab-badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 12px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.tab-badge[hidden] { display: none; }
nav.tabs button.on .tab-badge { background: var(--bg); color: var(--text); }
.sidebar .account { margin-top: auto; padding: 16px 18px; border-top: 1px solid var(--line); }
.sidebar .who { color: var(--muted); font-size: 12px; margin-bottom: 8px; word-break: break-all; }

main { flex: 1; min-width: 0; padding: 22px 28px 60px; }

/* 좁은 화면: 메뉴를 위로 올려 가로로 넘긴다 */
@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: auto; height: auto; position: static;
    flex-direction: row; flex-wrap: wrap; align-items: center;
    border-right: none; border-bottom: 1px solid var(--line);
  }
  .sidebar h1 { padding: 14px 16px; }
  .sidebar .account { margin: 0 0 0 auto; border-top: none; padding: 10px 16px; display: flex; gap: 8px; align-items: center; }
  .sidebar .who { margin: 0; }
  nav.tabs { order: 3; width: 100%; flex-direction: row; overflow-x: auto; padding: 0 10px 10px; }
  nav.tabs button { white-space: nowrap; }
  main { padding: 16px 16px 60px; }
}

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.chip {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 12px; font-weight: 500;
}
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .n { opacity: .6; margin-left: 4px; }

/* 표 */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line-soft); }
th { background: var(--surface); font-size: 12px; color: var(--muted); font-weight: 600; position: sticky; top: 0; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #fafafa; }
/* 눌러서 정렬·거르기 하는 표 머리 */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sortable.on { color: var(--text); }
/* 화살표·체크 자리는 늘 비워 둬서 눌러도 글자가 밀리지 않는다 */
th .arrow { display: inline-block; width: 1.2em; text-align: center; }

/* 열 폭 고정 표: 내용·정렬과 상관없이 크기가 그대로 */
table.fixed { table-layout: fixed; }
table.fixed td { overflow: hidden; text-overflow: ellipsis; }
table.fixed col.w-date { width: 160px; }
table.fixed col.w-state { width: 100px; }
table.fixed col.w-store { width: 170px; }
table.fixed col.w-email { width: 220px; }
table.fixed col.w-day { width: 120px; }
/* 사용자 탭 저장된 동의서·구독 칸 */
table.fixed col.w-half { width: 135px; }
/* 칸 사이 세로선 */
table.lined th, table.lined td { border-right: 1px solid var(--line); }
table.lined th:last-child, table.lined td:last-child { border-right: none; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
/* 칩 대신 글자색만 (칩은 줄 높이를 바꾼다) */
.text-ok { color: var(--ok); font-weight: 600; }
.text-warn { color: var(--warn); font-weight: 600; }
.text-danger { color: var(--danger); font-weight: 600; }
.text-none { color: var(--faint); }
.empty { padding: 40px; text-align: center; color: var(--faint); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid currentColor; }
.badge.ok { color: var(--ok); }
.badge.warn { color: var(--warn); }
.badge.danger { color: var(--danger); }
.badge.none { color: var(--faint); }

/* 상세 패널 */
.drawer-back { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 10; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw);
  background: var(--bg); z-index: 11; overflow-y: auto; padding: 22px 24px 40px;
  box-shadow: -8px 0 30px rgba(0,0,0,.08);
}
.drawer h2 { margin: 0 0 4px; font-size: 20px; }
.drawer h3 { font-size: 14px; margin: 24px 0 8px; }
.drawer .close { position: absolute; top: 16px; right: 16px; }
dl.fields { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; margin: 0; }
dl.fields dt { color: var(--muted); }
dl.fields dd { margin: 0; word-break: break-all; }
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; align-items: center; }
.notice { background: var(--surface); border-radius: 10px; padding: 12px; color: var(--body); line-height: 1.5; }

dialog { border: none; border-radius: 14px; padding: 22px; width: min(420px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.3); }
dialog h3 { margin: 0 0 12px; }
dialog textarea, dialog input { width: 100%; }
dialog .actions-row { justify-content: flex-end; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: #323232; color: #fff; padding: 10px 18px; border-radius: 999px; z-index: 20;
}

/* ── 탭 공용 추가 ── */
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.pre { white-space: pre-wrap; }
.ellipsis { max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
button.small { padding: 4px 10px; font-size: 12px; }
input.search { min-width: 240px; }
label.field { display: block; margin-bottom: 12px; }
label.field input, label.field textarea { width: 100%; margin-top: 4px; }
.drawer textarea { width: 100%; }

/* 앱 설정 카드 */
.card { border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; margin-bottom: 18px; max-width: 760px; }
.card h2 { font-size: 16px; margin: 0 0 6px; }
.setting { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line-soft); }
.setting > div:first-child { flex: 1; }
.setting-title { font-weight: 600; }


/* 대시보드 */
.dash-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.dash-head h2 { font-size: 20px; margin: 0; }
.dash-section h3 { font-size: 13px; color: var(--muted); margin: 22px 0 8px; font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
/* 맨 위: 사용자(원형, 오른쪽 두 줄 높이만큼) | 오른쪽 열(이번 달 예상 수익 / 처리할 일), 사이에 세로 구분선 */
.top-row { display: flex; gap: 24px; align-items: stretch; }
.top-row .group-users { display: flex; flex-direction: column; }
.top-row .group-right { flex: 1; min-width: 0; padding-left: 24px; border-left: 1px solid var(--line); }
.top-row .group-right .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
/* 처리할 일: 좁은 칸, 항목이 늘면 옆으로 이어지고 넘치면 다음 줄 */
.top-row .group-right .stats.todo { grid-template-columns: repeat(auto-fill, 150px); }
/* 숫자 칸은 높이·글자 크기를 똑같이 */
.top-row .stat { height: 110px; overflow: hidden; }
.top-row .stat-label { font-size: 13px; }
.top-row .stat-value { font-size: 26px; }
/* 예상 수익·처리할 일: 칸 이름은 왼쪽 위, 숫자는 칸 한가운데 */
.top-row .group-right .stat { position: relative; }
.top-row .group-right .stat-label { position: absolute; top: 10px; left: 12px; right: 12px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-row .group-right .stat-value { margin-top: 0; }
/* 칸 아래 작은 설명(stat의 note)은 왼쪽 아래 */
.top-row .group-right .stat .muted.small { position: absolute; bottom: 10px; left: 12px; right: 12px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* 사용자 원형: 가운데 전체 사용자 수, 검게 칠한 부분 = 구독자. 오른쪽 두 줄 높이를 다 쓴다 */
.top-row .users-card { flex: 1; height: auto; width: 260px; padding: 10px; }
svg.donut { width: 100%; height: 100%; max-height: 230px; }
svg.donut circle { fill: none; }
svg.donut .donut-rest { stroke: var(--line); }
svg.donut .donut-sub { stroke: var(--text); stroke-linecap: butt; }
svg.donut .donut-total { font-size: 20px; font-weight: 700; fill: var(--text); }
svg.donut .donut-sub-label { font-size: 9px; font-weight: 700; fill: var(--text); }
@media (max-width: 760px) {
  .top-row { flex-direction: column; }
  .top-row .group-right { padding-left: 0; border-left: none; }
  .top-row .group-right .stats { grid-template-columns: 1fr; }
  /* 폰처럼 좁은 화면에선 한 화면에 다 안 들어가니 스크롤을 허용한다 */
  main.dash-main { height: auto; overflow: visible; }
  .chart-section { min-height: 300px; }
}
.stat {
  border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
  background: var(--bg); color: var(--text); font-weight: 400;
  /* 카드 안은 가로·세로 모두 가운데 */
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
}
.stat.link:hover { border-color: var(--text); }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 4px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* 처리할 일이 남아 있으면 빨강 (메뉴 옆 숫자와 같은 색). 처리 끝난 상태 표시는 초록 */
.stat.hot { border-color: var(--danger); }
.stat.hot .stat-value { color: var(--danger); }

/* 목록 탭(템플릿·문의·사용자 — app.js FILL_TABS): 화면 높이에 맞추고 표 칸 안에서만 스크롤 */
main.fill-main { height: 100vh; display: flex; flex-direction: column; overflow: hidden; padding-bottom: 20px; }
main.fill-main > .toolbar { flex-shrink: 0; }
/* 세로 스크롤 막대를 늘 보이게 — 생겼다 없어지며 표 폭이 바뀌지 않도록 */
main.fill-main > .table-wrap { flex: 1; min-height: 0; overflow-x: auto; overflow-y: scroll; }
/* 빈 목록: 칸 한가운데 문구 */
.table-wrap.empty-box { display: flex; align-items: center; justify-content: center; }
.table-wrap.empty-box .empty { padding: 0; }
@media (max-width: 760px) {
  main.fill-main { height: auto; overflow: visible; }
  main.fill-main > .table-wrap { max-height: 70vh; }
}

/* 대시보드는 화면 높이에 맞춘다(스크롤 없음). 그래프 카드가 남는 영역을 다 채운다 */
main.dash-main { height: 100vh; display: flex; flex-direction: column; overflow: hidden; padding-bottom: 20px; }
.chart-section { flex: 1; min-height: 220px; display: flex; flex-direction: column; }
.chart-card { flex: 1; min-height: 0; max-width: none; margin: 0; display: flex; flex-direction: column; }
.chart-card .chart-wrap { flex: 1; min-height: 0; overflow: hidden; }
.chart-card > p { text-align: center; }
/* 왼쪽 위 달 넘기기 + 요약 */
.chart-head { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; }
.month-nav { display: flex; align-items: center; gap: 8px; }
.month-nav strong { min-width: 92px; text-align: center; }
.chart-head .chart-summary { margin: 0 0 0 auto; }
/* 평균: '평균 17.2'를 한 줄로 */
.chart-head .chart-summary > div { display: flex; align-items: baseline; gap: 6px; }
.chart-head .summary-value { margin-top: 0; }
svg.chart .axis.future { fill: var(--line); }
.chart-summary { display: flex; justify-content: center; gap: 28px; margin-bottom: 12px; text-align: center; }
.summary-value { font-size: 18px; font-weight: 700; margin-top: 2px; }
.chart-wrap { position: relative; }
svg.chart { display: block; }
svg.chart .grid { stroke: var(--line-soft); stroke-width: 1; }
svg.chart .axis { fill: var(--faint); font-size: 11px; }
svg.chart .bar { fill: #3a3a3a; }
svg.chart .bar.on { fill: #000; }
svg.chart .hit { fill: transparent; cursor: default; }
.chart-tip {
  position: absolute; top: 0; transform: translateX(-50%); pointer-events: none;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px;
  box-shadow: 0 4px 14px rgba(0,0,0,.08); white-space: nowrap;
}

/* 짧은 목록 (사용자 상세의 문의 등) */
ul.dash-list { list-style: none; margin: 0; padding: 0; }
ul.dash-list li { padding: 9px 4px; border-top: 1px solid var(--line-soft); }
ul.dash-list li.link { cursor: pointer; }
ul.dash-list li:first-child { border-top: none; }
ul.dash-list li.link:hover { background: #fafafa; }
ul.dash-list .ellipsis { max-width: 100%; white-space: nowrap; }
