/* 캠페인 레지스트리 — 라이트/다크 테마 (html[data-theme]로 전환, 기본은 시스템 설정) */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;          /* hover, 노트 배경 */
  --surface-3: #f2f4f7;          /* code, 비활성 칩 */
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #101828;
  --text-2: #475467;
  --muted: #98a2b3;
  --accent: #2c55d4;
  --accent-hover: #2347b8;
  --accent-soft: #eef2ff;
  --accent-soft-border: #c1cef5;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --danger-border: #fecdca;
  --ring: rgba(44, 85, 212, .18);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --radius: 10px;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%2398a2b3' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  /* 배지 팔레트 */
  --bdg-yellow-bg: #fffaeb; --bdg-yellow-fg: #b54708;
  --bdg-blue-bg:   #eff8ff; --bdg-blue-fg:   #175cd3;
  --bdg-green-bg:  #ecfdf3; --bdg-green-fg:  #067647;
  --bdg-gray-bg:   #f2f4f7; --bdg-gray-fg:   #475467;
  --bdg-red-bg:    #fef3f2; --bdg-red-fg:    #b42318;
  --bdg-purple-bg: #f4f3ff; --bdg-purple-fg: #5925dc;
  --bdg-orange-bg: #fff6ed; --bdg-orange-fg: #b93815;
  --nl-bg: linear-gradient(135deg, #eef2ff 0%, #f5f3ff 100%);
  --nl-border: #d6def8;
  --nl-text: #3538cd;
  color-scheme: light;
}
html[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1d212a;
  --surface-3: #232833;
  --border: #262b35;
  --border-strong: #363d4a;
  --text: #e6e8ec;
  --text-2: #b0b7c3;
  --muted: #7d8595;
  --accent: #4f8cff;
  --accent-hover: #6b9dff;
  --accent-soft: rgba(79, 140, 255, .14);
  --accent-soft-border: rgba(79, 140, 255, .35);
  --danger: #f0655f;
  --danger-soft: rgba(240, 68, 56, .12);
  --danger-border: rgba(240, 68, 56, .4);
  --ring: rgba(79, 140, 255, .28);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%237d8595' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --bdg-yellow-bg: rgba(247, 144, 9, .14);  --bdg-yellow-fg: #fdb022;
  --bdg-blue-bg:   rgba(46, 144, 250, .14); --bdg-blue-fg:   #6bb1ff;
  --bdg-green-bg:  rgba(18, 183, 106, .14); --bdg-green-fg:  #3ccb7f;
  --bdg-gray-bg:   rgba(152, 162, 179, .14);--bdg-gray-fg:   #b0b7c3;
  --bdg-red-bg:    rgba(240, 68, 56, .14);  --bdg-red-fg:    #f97066;
  --bdg-purple-bg: rgba(127, 86, 217, .16); --bdg-purple-fg: #b197fc;
  --bdg-orange-bg: rgba(239, 104, 32, .14); --bdg-orange-fg: #f38744;
  --nl-bg: linear-gradient(135deg, rgba(79, 140, 255, .10) 0%, rgba(127, 86, 217, .10) 100%);
  --nl-border: rgba(79, 140, 255, .25);
  --nl-text: #a4bcfd;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; }
body {
  margin: 0;
  font-family: "Pretendard Variable", "Pretendard", -apple-system, BlinkMacSystemFont,
    "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 14px; line-height: 1.55;
  transition: background .15s, color .15s;
}

/* ---------- header ---------- */
header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 28px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 28px; height: 60px;
}
.logo {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 15px; letter-spacing: -.01em;
  color: var(--text); text-decoration: none;
}
.logo img { height: 26px; width: auto; display: block; }
nav { display: flex; gap: 2px; flex: 1; align-items: center; }
nav a {
  color: var(--text-2); text-decoration: none; font-weight: 500;
  padding: 7px 13px; border-radius: 8px; font-size: 13.5px;
  white-space: nowrap;
  transition: background .12s, color .12s;
}
nav a:hover { background: var(--surface-3); color: var(--text); }
nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
nav a.btn-primary {
  background: var(--accent); color: #fff; margin-left: 10px; font-weight: 600;
  box-shadow: var(--shadow-sm);
}
nav a.btn-primary:hover { background: var(--accent-hover); color: #fff; }

#whoami { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-2); white-space: nowrap; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.role-chip {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border);
}
.role-chip.admin { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft-border); }
#whoami a { color: var(--muted); text-decoration: none; }
#whoami a:hover { color: var(--text-2); text-decoration: underline; }

/* 테마 토글 */
#theme-toggle {
  border: 1px solid var(--border); background: var(--surface);
  width: 32px; height: 32px; padding: 0; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 15px; line-height: 1; color: var(--text-2);
}
#theme-toggle:hover { background: var(--surface-2); }

main { max-width: 1140px; margin: 0 auto; padding: 28px 28px 64px; }

/* ---------- typography ---------- */
h1 { font-size: 20px; font-weight: 700; letter-spacing: -.015em; margin: 0 0 18px; }
h1 .hint { font-weight: 500; }
h2 {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 28px 0 10px;
}
a { color: var(--accent); }
code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px; background: var(--surface-3); border: 1px solid var(--border);
  padding: 1px 6px; border-radius: 5px; color: var(--text-2);
}

/* ---------- cards / stats ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 22px; margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}
.cards-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px; margin-bottom: 22px;
}
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm);
}
.stat .n { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
.stat .label { margin-top: 6px; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; padding: 9px 12px;
  color: var(--muted); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--surface-3); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; transition: background .1s; }
tr.clickable:hover { background: var(--surface-2); }
.empty-cell { color: var(--muted); text-align: center !important; padding: 28px 12px !important; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--bdg-gray-bg); color: var(--bdg-gray-fg);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.badge.리드     { background: var(--bdg-yellow-bg); color: var(--bdg-yellow-fg); }
.badge.확정     { background: var(--bdg-blue-bg);   color: var(--bdg-blue-fg); }
.badge.집행중   { background: var(--bdg-green-bg);  color: var(--bdg-green-fg); }
.badge.종료     { background: var(--bdg-gray-bg);   color: var(--bdg-gray-fg); }
.badge.홀드     { background: var(--bdg-red-bg);    color: var(--bdg-red-fg); }
.badge.일반     { background: var(--bdg-gray-bg);   color: var(--bdg-gray-fg); }
.badge.인수인계 { background: var(--bdg-purple-bg); color: var(--bdg-purple-fg); }
.badge.특이사항 { background: var(--bdg-orange-bg); color: var(--bdg-orange-fg); }

/* ---------- forms / controls ---------- */
input, select, textarea, button {
  font: inherit; color: var(--text);
  padding: 8px 12px; border: 1px solid var(--border-strong);
  border-radius: 8px; background: var(--surface);
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring);
}
/* select: 네이티브 화살표 제거 → 일관된 커스텀 셰브런 (우측 12px 고정) */
select {
  appearance: none; -webkit-appearance: none;
  background-image: var(--chevron);
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}
input[type="date"] { min-width: 0; }
textarea { width: 100%; min-height: 76px; resize: vertical; }
button { cursor: pointer; font-weight: 600; transition: background .12s, border-color .12s; }
button:hover { background: var(--surface-2); }
button.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: var(--shadow-sm);
}
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.danger { color: var(--danger); border-color: var(--danger-border); background: var(--surface); }
button.danger:hover { background: var(--danger-soft); }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 24px; }
.form-grid label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 12.5px; font-weight: 600; color: var(--text-2);
}
.form-grid .full { grid-column: 1 / -1; }
.form-grid input, .form-grid select { width: 100%; }

/* 저장 버튼: 폼 푸터 우측 정렬, 에러는 왼쪽에 */
.form-actions {
  display: flex; align-items: center; justify-content: flex-end; gap: 14px;
  margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--border);
}
.form-actions .error { flex: 1; margin: 0; text-align: right; }
.form-actions button { min-width: 96px; padding: 9px 18px; }

.media-checks { display: flex; flex-wrap: wrap; gap: 6px 8px; padding: 2px 0; }
.media-checks label {
  flex-direction: row; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 500; color: var(--text-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 5px 12px;
  cursor: pointer; transition: all .12s; user-select: none;
}
.media-checks label:hover { border-color: var(--border-strong); background: var(--surface-2); }
.media-checks label:has(input:checked) {
  background: var(--accent-soft); border-color: var(--accent-soft-border); color: var(--accent);
}
/* 체크박스 자체는 숨기고 pill 상태로만 표현 (포커스는 pill 링으로) */
.media-checks input { position: absolute; opacity: 0; pointer-events: none; }
.media-checks label:has(input:focus-visible) { box-shadow: 0 0 0 3px var(--ring); }
.media-checks label::before { content: "＋"; font-size: 11px; opacity: .6; }
.media-checks label:has(input:checked)::before { content: "✓"; opacity: 1; }

.filters { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filters input, .filters select { box-shadow: var(--shadow-sm); }

/* ---------- 자연어 입력 보조 ---------- */
.nl-box {
  background: var(--nl-bg);
  border: 1px solid var(--nl-border); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 18px;
}
.nl-box p { margin: 0 0 10px; font-size: 13px; color: var(--nl-text); }
.nl-row { display: flex; gap: 8px; }
.nl-row input { flex: 1; }
.nl-box .hint { margin-top: 8px; display: block; }

/* ---------- misc ---------- */
.hint { font-size: 12.5px; color: var(--muted); font-weight: 400; }
.error { color: var(--danger); font-size: 13px; margin: 10px 0; }
.error:empty { display: none; }

.note {
  position: relative; border-left: 2px solid var(--border-strong);
  padding: 10px 14px; margin: 12px 0 12px 5px; background: var(--surface-2);
  border-radius: 0 8px 8px 0;
}
.note::before {
  content: ""; position: absolute; left: -5.5px; top: 16px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--border-strong);
}
.note .meta { font-size: 12px; color: var(--muted); margin-bottom: 5px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.note .meta a { color: var(--muted); }
.note .body { white-space: pre-wrap; font-size: 13.5px; color: var(--text); }

.kv { font-size: 13.5px; line-height: 2.1; }
.kv b {
  display: inline-block; min-width: 96px;
  color: var(--muted); font-weight: 600; font-size: 12.5px;
}
.audit-row {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11.5px; color: var(--text-2);
  padding: 6px 0; border-bottom: 1px dashed var(--border);
  overflow-wrap: anywhere;
}
.audit-row:last-child { border-bottom: none; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; }
.toolbar h1 { margin: 0; }
.toolbar > span { display: flex; gap: 8px; }

@media (max-width: 960px) {
  .logo span { display: none; }
  #whoami > span:not(.avatar):not(.role-chip) { display: none; }
  header { gap: 16px; }
}
@media (max-width: 720px) {
  header { padding: 0 16px; gap: 14px; }
  .logo span { display: none; }
  main { padding: 20px 16px 48px; }
  .form-grid { grid-template-columns: 1fr; }
  .card { padding: 16px; overflow-x: auto; }
}
