/* 뉴로트레이닝센터 CRM — 모바일 우선. 진료 사이 폰으로 3초 안에 쓰는 화면. */

/* PART 9-2: hidden 속성이 display:flex 에 지지 않게 한다. 이 한 줄을 지우면
   로그인 화면 위에 빈 다이얼로그가 떠 있는 상태가 된다. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }

:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --line: #e3e6ea;
  --text: #16191d;
  --muted: #6b7280;
  --brand: #1f6feb;
  --brand-dark: #1858bd;
  --green: #12874a;
  --green-bg: #e6f5ec;
  --red: #d1333b;
  --red-bg: #fdeced;
  --amber: #a86400;
  --amber-bg: #fdf3e0;
  --gray-bg: #eef0f3;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .07), 0 1px 2px rgba(16, 24, 40, .04);
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont,
               'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ─────────── 로그인 ─────────── */
.login {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-box {
  width: 100%;
  max-width: 340px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 24px;
  text-align: center;
}
.login-title { margin: 0; font-size: 20px; }
.login-sub { margin: 4px 0 24px; color: var(--muted); font-size: 13px; }
.login-box form { display: flex; flex-direction: column; gap: 10px; }
.login-box input {
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.login-box input:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.login-box button {
  padding: 13px;
  border: 0;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
}
.login-box button:disabled { background: #9db8e6; }
.login-error {
  margin: 14px 0 0;
  color: var(--red);
  font-size: 13px;
}

/* ─────────── 상단바 / 탭바 ─────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 11px 14px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.topbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar-left strong { font-size: 15px; white-space: nowrap; }
.topbar-right { display: flex; gap: 6px; }
.role-badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--gray-bg);
  color: var(--muted);
  white-space: nowrap;
}
.role-badge.partner { background: #e8eefc; color: var(--brand-dark); }
.role-badge.client { background: var(--green-bg); color: var(--green); }

.icon-btn {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 12px;
  color: var(--muted);
}
.icon-btn.ghost { border-color: transparent; background: transparent; }
.icon-btn:disabled { opacity: .5; }

#main { padding: 12px 12px 84px; max-width: 720px; margin: 0 auto; }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  padding: 12px 4px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}
.tab.active { color: var(--brand); font-weight: 700; box-shadow: inset 0 2px 0 var(--brand); }

/* ─────────── 카드 / 통계 ─────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}
.card.warn { border: 1px solid #f3c9cc; background: var(--red-bg); }
.card-title {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}
.warn-note { margin: 0 0 10px; font-size: 12.5px; color: var(--red); }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 14px; }
.stat {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
}
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 22px; font-weight: 700; margin-top: 2px; letter-spacing: -.02em; }
.stat-value small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 2px; }

/* ─────────── 대기열 ─────────── */
.queue { margin-bottom: 18px; }
.queue-head {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 2px 8px;
  font-size: 14px;
  font-weight: 700;
}
.queue-desc { font-size: 12px; color: var(--muted); font-weight: 400; }
.badge {
  min-width: 20px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  text-align: center;
}
.badge.danger { background: var(--red); }
.badge.muted { background: var(--gray-bg); color: var(--muted); }
.badge.green { background: var(--green); }

.qcard {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  margin-bottom: 8px;
  overflow: hidden;
}
.qcard.stale::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--red);
}
.qcard.stale { padding-left: 16px; }

.qcard-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.qcard-name { font-size: 15px; font-weight: 700; }
.chip {
  padding: 1px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  background: var(--gray-bg);
  color: var(--muted);
}
.chip.now { background: #e8eefc; color: var(--brand-dark); }
.chip.red { background: var(--red-bg); color: var(--red); }
.chip.green { background: var(--green-bg); color: var(--green); }
.chip.amber { background: var(--amber-bg); color: var(--amber); }

.qcard-phone {
  display: inline-block;
  margin: 6px 0 2px;
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -.01em;
  color: var(--brand);
  text-decoration: none;
}
.qcard-time { margin: 6px 0 2px; font-size: 25px; font-weight: 700; letter-spacing: -.01em; }
.qcard-time.today { color: var(--green); }
.qcard-time.past { color: var(--red); }
.qcard-meta { font-size: 12.5px; color: var(--muted); }
.qcard-actions { display: flex; gap: 8px; margin-top: 10px; }
.qcard-foot { margin-top: 8px; text-align: right; }

.btn {
  flex: 1;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  font-size: 14px;
  font-weight: 600;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.good { background: var(--green); border-color: var(--green); color: #fff; }
.btn.ghost { background: #fff; color: var(--muted); }
.btn:disabled { opacity: .55; }

.inline-form { display: flex; gap: 8px; margin-top: 10px; }
.inline-form input { flex: 1; padding: 10px; border: 1px solid var(--line); border-radius: 9px; }
.notice { margin: 8px 0 0; font-size: 12px; color: var(--amber); }

.empty-all { text-align: center; color: var(--muted); padding: 48px 0; font-size: 14px; }

/* ─────────── 리스트 / 필터 ─────────── */
.filters { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.filters input, .filters select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.filter-row { display: flex; gap: 8px; }
.filter-row select { flex: 1; }
.list-count { margin: 0 2px 8px; font-size: 12px; color: var(--muted); }

.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}
.row-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.row-name { font-weight: 700; }
.row-meta { margin-top: 3px; font-size: 12.5px; color: var(--muted); }
.row-amount { font-weight: 700; }

.st { padding: 1px 7px; border-radius: 6px; font-size: 11px; font-weight: 600; }
.st-신규접수 { background: #e8eefc; color: var(--brand-dark); }
.st-통화시도중 { background: var(--amber-bg); color: var(--amber); }
.st-예약확정 { background: var(--green-bg); color: var(--green); }
.st-방문완료 { background: #e0f2f1; color: #00695c; }
.st-등록 { background: #ede7f6; color: #5e35b1; }
.st-보류육성 { background: #fff1e6; color: #b5540a; }
.st-종결 { background: var(--gray-bg); color: var(--muted); }

/* ─────────── 퍼널 ─────────── */
.stage { margin-bottom: 12px; }
.stage-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.stage-head b { font-size: 15px; }
.stage-bar { height: 10px; border-radius: 999px; background: var(--gray-bg); overflow: hidden; }
.stage-bar span { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.stage-rate { font-size: 12px; color: var(--muted); }
.chart-wrap { position: relative; height: 220px; }
.pill-row { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--gray-bg);
  font-size: 13px;
}
.pill b { margin-left: 4px; }
.kv { display: flex; justify-content: space-between; padding: 5px 0; font-size: 13.5px; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v.bad { color: var(--red); font-weight: 700; }

/* ─────────── 오버레이 (상세/다이얼로그) ─────────── */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  background: rgba(16, 24, 40, .45);
}
#detail { align-items: flex-end; justify-content: center; }
#schedule, #confirm { align-items: center; justify-content: center; padding: 20px; }

.sheet {
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
}
.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet-body { overflow-y: auto; padding: 12px; -webkit-overflow-scrolling: touch; }

.dialog {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: 14px;
  padding: 20px;
}
.dialog-title { margin: 0 0 4px; font-size: 17px; }
.dialog-target { margin: 0 0 14px; font-size: 14px; font-weight: 700; color: var(--brand-dark); }
.dialog-error { margin: 10px 0 0; color: var(--red); font-size: 13px; }
.dialog-actions { display: flex; gap: 8px; margin-top: 18px; }
.change-list { margin: 0; padding-left: 18px; font-size: 13.5px; }
.change-list li { margin-bottom: 4px; word-break: break-all; }
.alert {
  margin-top: 14px;
  padding: 11px 12px;
  border-radius: 9px;
  background: var(--amber-bg);
  color: #7a4a00;
  font-size: 13px;
  line-height: 1.45;
}

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.field textarea { min-height: 96px; resize: vertical; }

.detail-grid { display: grid; grid-template-columns: 88px 1fr; gap: 6px 10px; font-size: 13.5px; }
.detail-grid dt { color: var(--muted); }
.detail-grid dd { margin: 0; word-break: break-all; }
.detail-grid a { color: var(--brand); text-decoration: none; font-weight: 600; }

.audit {
  margin: 0;
  padding: 10px;
  background: var(--gray-bg);
  border-radius: 9px;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 180px;
  overflow-y: auto;
}
.timeline { display: flex; flex-direction: column; gap: 7px; }
.tl-item { display: flex; gap: 8px; align-items: baseline; font-size: 13px; }
.tl-time { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ─────────── 토스트 / 로딩 ─────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 86px;
  transform: translateX(-50%);
  z-index: 60;
  max-width: 88vw;
  padding: 11px 16px;
  border-radius: 999px;
  background: #16191d;
  color: #fff;
  font-size: 13.5px;
  text-align: center;
}
.toast.bad { background: var(--red); }
.loading {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(244, 245, 247, .55);
}
.loading span {
  width: 32px; height: 32px;
  border: 3px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 600px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
  .filters { flex-direction: row; }
  .filters input { flex: 2; }
  .filter-row { flex: 3; }
  .sheet { border-radius: 16px; max-height: 86vh; margin-bottom: 24px; }
  .sheet-head { border-radius: 16px 16px 0 0; }
}
