/* =========================================================
   관리자 화면 공통 스타일
   색상/간격은 :root 변수만 바꾸면 전체에 반영됩니다.
   ========================================================= */
:root {
  --ink: #111827;          /* 제목, 주요 버튼, 활성 메뉴 */
  --bg: #f9fafb;           /* 화면 배경 */
  --surface: #ffffff;
  --line: #e5e7eb;
  --line-soft: #f0f1f3;
  --text: #1f2937;
  --muted: #6b7280;
  --radius: 12px;
  --sidebar-w: 240px;

  /* 아이콘/배지용 색 (배경, 글자) */
  --blue-bg: #eff6ff;   --blue: #2563eb;
  --green-bg: #ecfdf3;  --green: #15803d;
  --amber-bg: #fef9c3;  --amber: #a16207;
  --red-bg: #fef2f2;    --red: #dc2626;
  --purple-bg: #f5f3ff; --purple: #7c3aed;
  --gray-bg: #f3f4f6;   --gray: #4b5563;

  --bs-body-font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont,
    "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --bs-body-color: var(--text);
  --bs-body-bg: var(--bg);
  --bs-border-color: var(--line);
  --bs-link-color-rgb: 37, 99, 235;
  --bs-link-hover-color-rgb: 29, 78, 216;
}

body { font-size: 14px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
a { text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ---------- Bootstrap 덮어쓰기 ---------- */
.btn { font-weight: 600; border-radius: 8px; }
.btn:hover { text-decoration: none; }
.btn-primary {
  --bs-btn-bg: var(--ink); --bs-btn-border-color: var(--ink);
  --bs-btn-hover-bg: #000; --bs-btn-hover-border-color: #000;
  --bs-btn-active-bg: #000; --bs-btn-active-border-color: #000;
  --bs-btn-disabled-bg: var(--ink); --bs-btn-disabled-border-color: var(--ink);
}
.btn-light {
  --bs-btn-bg: var(--surface); --bs-btn-border-color: var(--line);
  --bs-btn-hover-bg: var(--gray-bg); --bs-btn-hover-border-color: #d1d5db;
  --bs-btn-color: var(--text);
}
.btn-ghost-danger {
  --bs-btn-color: var(--red); --bs-btn-bg: transparent; --bs-btn-border-color: transparent;
  --bs-btn-hover-bg: var(--red-bg); --bs-btn-hover-color: var(--red); --bs-btn-hover-border-color: transparent;
  font-weight: 500;
}
.form-control, .form-select { border-radius: 8px; border-color: var(--line); background-color: #fff; }
.form-control:focus, .form-select:focus { border-color: #9ca3af; box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.08); }
.form-label { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.form-hint { color: var(--muted); font-size: 12.5px; margin-top: 6px; }

/* ---------- 사이드바 ---------- */
.app-sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; z-index: 1040;
}
.app-brand { display: flex; align-items: center; gap: 10px; padding: 22px 20px; color: var(--ink); }
.app-brand:hover { text-decoration: none; color: var(--ink); }
.app-brand-mark {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: #f5b82e; color: #fff; display: grid; place-items: center; font-size: 17px;
}
.app-brand-name { font-weight: 700; font-size: 15px; line-height: 1.2; }
.app-brand-sub { font-size: 12px; color: var(--muted); line-height: 1.2; }

.app-nav { flex: 1; overflow-y: auto; padding: 4px 14px 16px; }
.app-nav-group { font-size: 12px; color: #9ca3af; padding: 16px 10px 6px; font-weight: 500; }
.app-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; margin-bottom: 2px; border-radius: 8px;
  color: #374151; font-weight: 500;
}
.app-nav a i { font-size: 16px; }
.app-nav a:hover { background: var(--gray-bg); color: var(--ink); text-decoration: none; }
.app-nav a.active { background: var(--ink); color: #fff; }

.app-sidebar-foot {
  border-top: 1px solid var(--line); padding: 14px 20px; font-size: 13px;
  display: flex; align-items: center; justify-content: space-between; color: var(--muted);
}
.app-sidebar-foot form { margin: 0; }
.app-sidebar-foot button { background: none; border: 0; color: var(--muted); padding: 0; font-size: 13px; }
.app-sidebar-foot button:hover { color: var(--red); }

.app-main { margin-left: var(--sidebar-w); min-height: 100vh; }
.app-topbar { display: none; }
.app-content { max-width: 1320px; margin: 0 auto; padding: 32px 40px 64px; }

/* ---------- 페이지 제목 ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-title { font-size: 24px; font-weight: 700; color: var(--ink); margin: 0; letter-spacing: -0.02em; }
.page-sub { color: var(--muted); margin: 4px 0 0; }
.page-meta { color: var(--muted); font-size: 12.5px; }
.back-link { color: var(--muted); font-size: 13px; display: inline-flex; gap: 4px; margin-bottom: 8px; }
.back-link:hover { color: var(--text); }

/* ---------- 카드(패널) ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04); margin-bottom: 20px;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--line-soft);
}
.panel-title { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 700; margin: 0; color: var(--ink); }
.panel-title-icon { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font-size: 12px; color: #fff; }
.panel-body { padding: 20px; }
.panel-note { color: var(--muted); font-size: 13px; }

/* ---------- KPI 카드 ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  padding: 18px 20px; display: flex; justify-content: space-between; gap: 12px; min-height: 112px;
}
.kpi-label { color: var(--muted); font-size: 13px; }
.kpi-value { font-size: 24px; font-weight: 700; color: var(--ink); letter-spacing: -0.02em; line-height: 1.4; margin: 2px 0 6px; }
.kpi-value small { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.kpi-icon { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 18px; flex: none; }
.kpi-delta { font-size: 12.5px; font-weight: 600; margin-left: 4px; }
.kpi-delta.up { color: var(--green); }
.kpi-delta.down { color: var(--red); }

/* 색 조합 (아이콘, 배지 공용) */
.tone-blue { background: var(--blue-bg); color: var(--blue); }
.tone-green { background: var(--green-bg); color: var(--green); }
.tone-amber { background: var(--amber-bg); color: var(--amber); }
.tone-red { background: var(--red-bg); color: var(--red); }
.tone-purple { background: var(--purple-bg); color: var(--purple); }
.tone-gray { background: var(--gray-bg); color: var(--gray); }

.badge-soft { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 6px; }

/* ---------- 상태 표시 ---------- */
.status { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 6px; white-space: nowrap; }
.status-OPEN { background: var(--green-bg); color: var(--green); }
.status-SCHEDULED { background: var(--amber-bg); color: var(--amber); }
.status-CLOSED { background: var(--gray-bg); color: var(--gray); }

.chip { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--gray-bg); color: var(--gray); font-weight: 500; border: 1px solid var(--line); }

/* ---------- 응답 진행 막대 ---------- */
.meter { display: flex; align-items: center; gap: 10px; min-width: 160px; }
.meter-track { flex: 1; height: 8px; border-radius: 99px; background: #eef0f3; overflow: hidden; }
.meter-fill { height: 100%; background: var(--green); border-radius: 99px; }
.meter-text { font-size: 12.5px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.meter-text strong { color: var(--text); }
.meter-lg .meter-track { height: 12px; }

.due { font-size: 12.5px; font-weight: 600; white-space: nowrap; color: var(--muted); }
.due.soon { color: var(--red); }

/* ---------- 표 ---------- */
.table-app { margin: 0; --bs-table-bg: transparent; }
.table-app > thead th {
  font-size: 12.5px; font-weight: 600; color: var(--muted); background: #fafafa;
  border-bottom: 1px solid var(--line); padding: 10px 16px; white-space: nowrap;
}
.table-app > tbody td { padding: 12px 16px; vertical-align: middle; border-color: var(--line-soft); }
.table-app > tbody tr:last-child td { border-bottom: 0; }
.table-app > tbody tr:hover td { background: #fafafa; }
.table-app .cell-strong { font-weight: 600; color: var(--ink); }
.table-app .cell-muted { color: var(--muted); }
.table-app th[title] { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.table-scroll { overflow-x: auto; }

/* ---------- 공유 링크 ---------- */
.share {
  display: flex; align-items: center; gap: 8px; max-width: 460px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 4px 4px 4px 12px;
}
.share code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-size: 13px; }
.share .btn { padding: 4px 10px; font-size: 12.5px; }
.btn-copy.copied { color: var(--green); border-color: var(--green); }

/* ---------- 문항 목록 ---------- */
.question-list { list-style: none; margin: 0; padding: 0; counter-reset: q; }
.question-item { display: grid; grid-template-columns: 28px 1fr auto; gap: 12px; padding: 14px 20px; border-top: 1px solid var(--line-soft); align-items: start; }
.question-item:first-child { border-top: 0; }
.question-item::before {
  counter-increment: q; content: counter(q);
  width: 24px; height: 24px; border-radius: 50%; background: var(--gray-bg); color: var(--gray);
  font-size: 12px; font-weight: 700; display: grid; place-items: center;
}
.question-text { font-weight: 600; color: var(--ink); }
.question-options { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }

/* ---------- 목록형 ---------- */
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 20px; border-top: 1px solid var(--line-soft); }
.list-plain li:first-child { border-top: 0; }
.list-scroll { max-height: 340px; overflow-y: auto; }

/* 차트 옆 범례 (레퍼런스의 Gold/Diamond/Silver 카드 형태) */
.legend-list { display: grid; gap: 8px; }
.legend-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; background: var(--bg); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.legend-name { flex: 1; font-weight: 600; }
.legend-num { text-align: right; font-weight: 700; color: var(--ink); line-height: 1.2; }
.legend-num small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }

/* ---------- 빈 상태 / 알림 ---------- */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }
.empty .btn { margin-top: 14px; }

.flash { display: flex; gap: 10px; align-items: flex-start; padding: 12px 16px; border-radius: 8px; margin-bottom: 20px; font-weight: 500; }
.flash-success { background: var(--green-bg); color: var(--green); }
.flash-error { background: var(--red-bg); color: var(--red); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters .form-select, .filters .form-control { width: auto; min-width: 160px; }

.modal-content { border: 0; border-radius: 14px; }
.modal-header, .modal-footer { border-color: var(--line-soft); }

/* ---------- 로그인 ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 36px 32px; box-shadow: 0 8px 24px rgba(16, 24, 40, 0.06); }
.login-card .app-brand { padding: 0 0 24px; }

/* ---------- 반응형 ---------- */
@media (max-width: 1199.98px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); transition: transform 0.2s ease; }
  body.nav-open .app-sidebar { transform: none; }
  body.nav-open .app-backdrop { display: block; }
  .app-backdrop { display: none; position: fixed; inset: 0; background: rgba(17, 24, 39, 0.35); z-index: 1030; }
  .app-main { margin-left: 0; }
  .app-topbar {
    display: flex; align-items: center; gap: 12px; height: 56px; padding: 0 16px;
    background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 1020;
  }
  .app-topbar button { background: none; border: 0; font-size: 22px; color: var(--ink); padding: 4px; }
  .app-content { padding: 24px 16px 48px; }
}
@media (max-width: 575.98px) {
  .kpi-grid { gap: 10px; }
  .kpi { padding: 14px; min-height: 0; }
  .kpi-icon { width: 32px; height: 32px; font-size: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  .app-sidebar { transition: none; }
}
