/* ===== 우두머리 SMP 대시보드 — 모바일 우선 ===== */
:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1a1d21;
  --muted: #7a828c;
  --line: #e4e7ec;
  --accent: #2f6bff;
  --accent-soft: #e8efff;
  --danger: #e5484d;
  --danger-soft: #fdebec;
  --ok: #2e9e5b;
  --ok-soft: #e6f6ec;
  --warn: #b98900;
  --warn-soft: #fdf5dd;
  --radius: 14px;
  --tabbar-h: 58px;
}

* { box-sizing: border-box; }
/* hidden 속성이 display:flex 등 CSS에 지지 않도록 강제 */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Pretendard Variable", Pretendard, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 15px; }
h2 { font-size: 16px; font-weight: 700; margin: 22px 4px 10px; }
.h2-sub { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.muted { color: var(--muted); font-size: 13px; }

/* ===== 로그인 ===== */
#login-screen {
  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);
  padding: 32px 24px; text-align: center;
  box-shadow: 0 4px 24px rgba(0,0,0,.06);
}
.login-box h1 { margin: 0; font-size: 22px; }
.login-sub { margin: 4px 0 24px; color: var(--muted); font-size: 13px; }
#login-form { display: flex; flex-direction: column; gap: 10px; }
#login-key {
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px;
  text-align: center; letter-spacing: 2px;
}
#login-btn {
  padding: 12px; border: none; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 600;
}
#login-btn:disabled { opacity: .5; }
.login-error { color: var(--danger); font-size: 13px; margin: 12px 0 0; }

/* ===== 상단바 / 탭바 ===== */
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 12px 16px;
}
.brand { font-weight: 800; font-size: 16px; margin-right: auto; }
.role-badge {
  font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent);
}
.icon-btn {
  border: 1px solid var(--line); background: var(--card);
  border-radius: 8px; width: 34px; height: 34px; font-size: 15px;
  color: var(--muted);
}

#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-btn {
  flex: 1; padding: 14px 0 12px; border: none; background: none;
  font-size: 13px; font-weight: 600; color: var(--muted);
  border-top: 2px solid transparent;
}
.tab-btn.active { color: var(--accent); border-top-color: var(--accent); }

#main {
  padding: 14px 14px calc(var(--tabbar-h) + 24px);
  max-width: 760px; margin: 0 auto;
}

/* ===== 카드 ===== */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-card {
  background: var(--card); border-radius: var(--radius); padding: 14px 16px;
  border: 1px solid var(--line);
}
.stat-card .label { font-size: 12px; color: var(--muted); }
.stat-card .value { font-size: 24px; font-weight: 800; margin-top: 2px; }
.stat-card .value small { font-size: 13px; font-weight: 600; color: var(--muted); }

/* ===== 리스트 ===== */
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; display: flex; align-items: center; gap: 10px;
}
.row.clickable { cursor: pointer; }
.row.clickable:active { background: #fafbfc; }
.row .grow { flex: 1; min-width: 0; }
.row .name { font-weight: 700; }
.row .sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.row-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 18px 0; }

.badge {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 99px; white-space: nowrap;
}
.badge.b-default { background: #eef0f3; color: var(--muted); }
.badge.b-blue { background: var(--accent-soft); color: var(--accent); }
.badge.b-green { background: var(--ok-soft); color: var(--ok); }
.badge.b-red { background: var(--danger-soft); color: var(--danger); }
.badge.b-warn { background: var(--warn-soft); color: var(--warn); }

.btn-small {
  border: 1px solid var(--accent); color: var(--accent); background: var(--card);
  border-radius: 8px; padding: 6px 12px; font-size: 13px; font-weight: 600;
  white-space: nowrap;
}
.btn-small:active { background: var(--accent-soft); }

/* ===== 필터 ===== */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters select, .filters input {
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card);
}
.filters select { flex: 1; min-width: 100px; }
.filters input { flex: 2; min-width: 160px; }

/* ===== 퍼널 ===== */
#funnel-bars { display: flex; flex-direction: column; gap: 6px; }
.funnel-row { display: flex; align-items: center; gap: 8px; }
.funnel-label { width: 82px; font-size: 12px; font-weight: 600; text-align: right; flex-shrink: 0; }
.funnel-track { flex: 1; background: #edeff2; border-radius: 6px; height: 26px; position: relative; }
.funnel-fill {
  height: 100%; border-radius: 6px; background: var(--accent);
  min-width: 2px; opacity: .85;
}
.funnel-nums { width: 110px; font-size: 12px; flex-shrink: 0; }
.funnel-nums b { font-size: 13px; }
.funnel-rate { color: var(--muted); }
.chart-wrap {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; height: 240px;
}

/* ===== 상세 패널 ===== */
#detail-overlay, #confirm-overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(20,22,26,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
#detail-panel {
  background: var(--bg); width: 100%; max-width: 760px;
  max-height: 92dvh; overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 0 16px 32px;
}
.detail-head {
  position: sticky; top: 0; background: var(--bg); z-index: 5;
  display: flex; align-items: center; gap: 10px; padding: 14px 0 10px;
  border-bottom: 1px solid var(--line);
}
.detail-head h3 { margin: 0; font-size: 17px; flex: 1; }
.pii-toggle { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; white-space: nowrap; }

.detail-section { margin-top: 16px; }
.detail-section h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 700; }
.kv-grid {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 4px 14px;
}
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--muted); flex-shrink: 0; }
.kv .v { text-align: right; word-break: break-all; }

.timeline { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.tl-item { display: flex; gap: 10px; align-items: center; padding: 5px 0; font-size: 13px; }
.tl-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex-shrink: 0; }
.tl-item.sent .tl-dot { background: var(--ok); }
.tl-item .tl-name { width: 110px; font-weight: 600; }
.tl-item .tl-time { color: var(--muted); }

/* ===== 수정 폼 ===== */
.edit-form {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; display: flex; flex-direction: column; gap: 12px;
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; font-weight: 700; color: var(--muted); }
.field input, .field select, .field textarea {
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff;
}
.field textarea { min-height: 72px; resize: vertical; }
.field-check { flex-direction: row; align-items: center; gap: 8px; }
.field-check label { font-size: 14px; font-weight: 600; color: var(--ink); }
.audit-log {
  background: #f8f9fa; border-radius: 8px; padding: 10px 12px;
  font-size: 12px; color: var(--muted); white-space: pre-wrap; word-break: break-all;
}
.btn-primary {
  padding: 12px; border: none; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 700;
}
.btn-primary:disabled { opacity: .5; }
.btn-secondary {
  padding: 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--ink); font-size: 15px; font-weight: 600;
}

/* ===== 확인 다이얼로그 ===== */
#confirm-overlay { align-items: center; padding: 20px; }
#confirm-box {
  background: var(--card); border-radius: 16px; padding: 20px;
  width: 100%; max-width: 400px; max-height: 80dvh; overflow-y: auto;
}
#confirm-box h3 { margin: 0 0 12px; font-size: 16px; }
#confirm-changes { font-size: 14px; display: flex; flex-direction: column; gap: 6px; }
.change-line { display: flex; justify-content: space-between; gap: 10px; }
.change-line .ck { color: var(--muted); }
#confirm-warnings { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.warning-box {
  background: var(--warn-soft); color: #7a5b00; border-radius: 10px;
  padding: 10px 12px; font-size: 13px; font-weight: 600;
}
.confirm-actions { display: flex; gap: 8px; margin-top: 16px; }
.confirm-actions button { flex: 1; }

/* ===== 토스트 ===== */
#toast {
  position: fixed; bottom: calc(var(--tabbar-h) + 16px); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 99px;
  font-size: 13px; font-weight: 600; z-index: 60; white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
}

/* ===== 데스크톱 ===== */
@media (min-width: 761px) {
  #tabbar {
    position: sticky; top: 59px; bottom: auto;
    max-width: 760px; margin: 0 auto;
    border: 1px solid var(--line); border-radius: 0 0 12px 12px;
  }
  .tab-btn { border-top: none; border-bottom: 2px solid transparent; }
  .tab-btn.active { border-bottom-color: var(--accent); }
  #main { padding-bottom: 40px; }
  .cards { grid-template-columns: repeat(4, 1fr); }
  #detail-overlay { align-items: center; padding: 24px; }
  #detail-panel { border-radius: 18px; max-height: 86dvh; }
  #toast { bottom: 32px; }
}
