/* INSPIRAIN ADS — 디자인 시스템
   team.inspirain.kr 의 브랜드 톤앤매너(inspirain 테마)를 따른다:
   다크 네이비/틸 배경 + 오렌지 액센트 + Pretendard. */
:root {
  --bg: #16232b;
  --surface: #143037;
  --surface-2: #0f272e;
  --line: #274b54;
  --line2: #1d3d45;
  --text: #f5f3ec;
  --muted: #9db0b5;
  --faint: #6f868d;
  --accent: #e8531f;
  --accent-soft: #3a2114;
  --accent-line: #7a3a1c;
  --ok: #2eb88a;
  --ok-soft: #12352c;
  --warn: #f2a33c;
  --warn-soft: #3a2d13;
  --danger: #e26d6d;
  --danger-soft: #3a1c1c;
  --google: #4573d2;
  --meta: #7b68ee;
  --shadow: 0 1px 2px rgba(0,0,0,.45), 0 8px 22px rgba(0,0,0,.40);
  --radius: 12px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* .gate(grid)·#app(flex)의 display 지정이 hidden 을 이기지 못하게 */
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont,
    "Apple SD Gothic Neo", "Malgun Gothic", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }
a { color: var(--accent); text-decoration: none; }

/* ── 앱 레이아웃: 사이드바 + 메인 ── */
#app { display: flex; min-height: 100vh; }
.sidebar {
  width: 216px;
  flex: none;
  background: var(--surface-2);
  border-right: 1px solid var(--line2);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 8px 16px;
}
.brand .logo {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #f2a33c);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 13px;
  color: #fff;
}
.brand .name { font-weight: 700; font-size: 14.5px; letter-spacing: -0.01em; }
.brand .name small { display: block; font-size: 10.5px; color: var(--faint); font-weight: 500; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13.5px;
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.nav-item:hover { background: var(--line2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.nav-item .badge {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 7px;
}
.sidebar .spacer { flex: 1; }

/* ── 상단바 ── */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line2);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.topbar .right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.content { padding: 20px 22px 60px; max-width: 1240px; width: 100%; margin: 0 auto; }

/* ── 공통 컴포넌트 ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--line2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.panel-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel-title .count { color: var(--faint); font-weight: 500; text-transform: none; letter-spacing: 0; }

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); color: #fff; }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: default; }

select.ctl, input.ctl {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
}
select.ctl:focus, input.ctl:focus { outline: none; border-color: var(--accent); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  border-radius: 999px;
  padding: 3px 10px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--surface-2);
}
.chip.ok { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }
.chip.warn { color: var(--warn); border-color: var(--warn); background: var(--warn-soft); }
.chip.danger { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
.chip.google { color: #8fb0ec; border-color: var(--google); }
.chip.meta { color: #b0a5f5; border-color: var(--meta); }

/* KPI 카드 그리드 */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(178px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--line2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 15px 12px;
}
.kpi .k { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.kpi .v { font-size: 22px; font-weight: 750; letter-spacing: -0.02em; }
.kpi .v.accent { color: var(--accent); }
.kpi .v.ok { color: var(--ok); }
.kpi .d { font-size: 11.5px; margin-top: 5px; color: var(--faint); }
.kpi .d.up { color: var(--ok); }
.kpi .d.down { color: var(--danger); }

/* 표 */
.tbl-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--line2); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--surface); }
.tbl th, .tbl td { padding: 10px 12px; text-align: right; white-space: nowrap; }
.tbl th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  border-bottom: 1px solid var(--line2);
  position: sticky; top: 0;
}
.tbl td:first-child, .tbl th:first-child { text-align: left; }
.tbl tbody tr { border-bottom: 1px solid var(--line2); }
.tbl tbody tr:last-child { border-bottom: none; }
.tbl tbody tr:hover { background: var(--line2); }
.tbl .name-cell { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }

/* 배너 */
.banner {
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: 13px;
  margin-bottom: 14px;
  border: 1px solid var(--warn);
  background: var(--warn-soft);
  color: #f3d9a8;
}
.banner.info { border-color: var(--google); background: #16283f; color: #b9cdf0; }

/* 인사이트 */
.insight {
  display: flex;
  gap: 11px;
  padding: 13px 14px;
  border: 1px solid var(--line2);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 10px;
}
.insight .sev { flex: none; font-size: 17px; }
.insight .body { min-width: 0; flex: 1; }
.insight .title { font-weight: 700; font-size: 13.5px; margin-bottom: 3px; }
.insight .detail { color: var(--muted); font-size: 12.5px; }
.insight .suggest {
  margin-top: 7px;
  font-size: 12.5px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: 9px;
  padding: 7px 10px;
  color: #f0b9a0;
}
.insight .meta-line { margin-top: 6px; font-size: 11px; color: var(--faint); display: flex; gap: 8px; flex-wrap: wrap; }

/* 로그인 화면 */
.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.gate-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line2);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 36px 30px;
  text-align: center;
}
.gate-card .logo {
  width: 52px; height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), #f2a33c);
  display: grid; place-items: center;
  margin: 0 auto 16px;
  font-weight: 800; font-size: 21px; color: #fff;
}
.gate-card h1 { font-size: 19px; margin: 0 0 6px; }
.gate-card p { color: var(--muted); font-size: 13px; margin: 0 0 22px; }
.google-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: #1e1f21;
  font-weight: 700;
  font-size: 14px;
  border-radius: 10px;
  padding: 11px 22px;
  cursor: pointer;
}
.google-btn:hover { filter: brightness(0.95); }
.google-btn img { width: 18px; height: 18px; }

/* 사용자 칩 */
.user-chip {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--muted);
  border: 1px solid var(--line2);
  border-radius: 999px;
  padding: 4px 12px 4px 5px;
}
.user-chip img { width: 24px; height: 24px; border-radius: 50%; }

/* 언어 전환 */
.lang-switch { display: flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.lang-switch button {
  border: none; background: transparent; color: var(--muted);
  padding: 6px 11px; font-size: 12px; cursor: pointer;
}
.lang-switch button.on { background: var(--accent); color: #fff; font-weight: 700; }

/* 폼 */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select {
  width: 100%;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 10px; font-size: 13px; font-family: inherit;
}
.field input:focus { outline: none; border-color: var(--accent); }

/* 플랫폼 도트 */
.pdot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.pdot.google { background: var(--google); }
.pdot.meta { background: var(--meta); }

/* 광고주 리포트 (외부 열람용 단독 페이지 레이아웃) */
.report-shell { max-width: 1080px; margin: 0 auto; padding: 26px 20px 80px; }
.report-head {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding-bottom: 18px; margin-bottom: 20px;
  border-bottom: 1px solid var(--line2);
}
.report-head h1 { font-size: 21px; margin: 0; letter-spacing: -0.02em; }
.report-head .sub { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.report-head .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.section-label {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--faint); margin: 22px 2px 10px;
}

.empty-note { text-align: center; color: var(--faint); padding: 26px 0; font-size: 13px; }

/* ── 캠페인 뷰 ── */
.camp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; }
.camp-card {
  background: var(--surface); border: 1px solid var(--line2); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 15px 16px 13px; cursor: pointer;
  transition: border-color .12s ease;
}
.camp-card:hover { border-color: var(--accent); }
.camp-head { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 8px; }
.camp-head .names { min-width: 0; flex: 1; }
.camp-adv { font-size: 11.5px; color: var(--muted); }
.camp-name { font-size: 14.5px; font-weight: 750; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.camp-stats { display: flex; gap: 14px; flex-wrap: wrap; margin: 9px 0 4px; }
.camp-stat .k { font-size: 10.5px; color: var(--faint); }
.camp-stat .v { font-size: 13.5px; font-weight: 700; }
.camp-meta-line { font-size: 11.5px; color: var(--muted); margin-top: 6px; display: flex; flex-direction: column; gap: 2px; }
.camp-meta-line b { color: var(--text); font-weight: 600; }
.camp-note { color: var(--warn); }

/* 상태 등급 칩 */
.grade { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 750;
  border-radius: 999px; padding: 3px 10px; border: 1px solid; flex: none; }
.grade.good { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }
.grade.ok   { color: var(--google); border-color: var(--google); background: #16283f; }
.grade.warn { color: var(--warn); border-color: var(--warn); background: var(--warn-soft); }
.grade.bad  { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }

/* AI 비서 분석 배너 */
.ai-note {
  display: flex; gap: 11px; align-items: flex-start;
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid var(--accent-line); border-left: 3px solid var(--accent);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px;
}
.ai-note .ico { flex: none; font-size: 18px; }
.ai-note .body { min-width: 0; }
.ai-note .ttl { font-size: 12px; font-weight: 750; color: var(--accent); margin-bottom: 5px; letter-spacing: .04em; }
.ai-note p { margin: 0 0 6px; font-size: 13px; line-height: 1.6; color: var(--text); }
.ai-note p:last-child { margin-bottom: 0; }

/* 상세: 메타 정보 편집 폼 */
.meta-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.meta-form .field.wide { grid-column: 1 / -1; }

/* 표/차트 토글 */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { border: none; background: transparent; color: var(--muted); padding: 6px 12px; font-size: 12px; cursor: pointer; }
.seg button.on { background: var(--accent); color: #fff; font-weight: 700; }

/* 외부 링크 아이콘 */
.ext-link { color: var(--google); text-decoration: none; font-size: 12px; white-space: nowrap; }
.ext-link:hover { text-decoration: underline; }

/* 토스트 알림 (저장/동기화 완료 피드백) */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--surface);
  border: 1px solid var(--ok);
  color: var(--ok);
  font-size: 13.5px;
  font-weight: 700;
  border-radius: 999px;
  padding: 10px 20px;
  box-shadow: var(--shadow);
  z-index: 999;
  opacity: 0;
  transition: opacity .18s ease, transform .18s ease;
  pointer-events: none;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: var(--danger); color: var(--danger); }

/* ── 모바일 반응형 ── */
@media (max-width: 760px) {
  #app { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: sticky; top: 0; z-index: 30;
    flex-direction: row; align-items: center; gap: 2px;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    padding: 8px 10px; border-right: none; border-bottom: 1px solid var(--line2);
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .brand { padding: 0 6px 0 0; flex: none; }
  .brand .name { display: none; }              /* 모바일은 로고만 */
  #nav { display: flex; flex-direction: row; gap: 2px; flex: none; }  /* 세로 쌓임 버그 수정 */
  .nav-item { width: auto; white-space: nowrap; padding: 8px 11px; font-size: 13px; flex: none; }
  .sidebar .spacer, .sidebar .foot { display: none; }

  .topbar { flex-wrap: wrap; gap: 8px; padding: 10px 14px; position: static; }
  .topbar h1 { width: 100%; font-size: 16px; }
  .topbar .right { margin-left: 0; width: 100%; flex-wrap: wrap; gap: 6px; }
  .topbar .right > * { flex: none; }
  .user-chip span { max-width: 90px; overflow: hidden; text-overflow: ellipsis; }

  .content { padding: 12px 12px 50px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .kpi { padding: 11px 12px 10px; }
  .kpi .v { font-size: 18px; }
  .panel { padding: 12px; }
  .form-grid { grid-template-columns: 1fr; }
  .tbl th, .tbl td { padding: 8px 8px; font-size: 12px; }
  .report-shell { padding: 16px 12px 60px; }
  .report-head { flex-direction: column; align-items: flex-start; }
  .report-head .right { margin-left: 0; flex-wrap: wrap; }
  .camp-grid { grid-template-columns: 1fr; }
}
