/* ===== 기본 ===== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Pretendard', 'Apple SD Gothic Neo', 'Noto Sans KR', system-ui, -apple-system, sans-serif;
  color: #1f2937;
  background: #f3f4f6;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  word-break: keep-all;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

:root {
  --primary: #1e3a8a;
  --primary-dark: #172554;
  --accent: #b08d57;
  --danger: #dc2626;
  --success: #059669;
  --border: #e5e7eb;
  --muted: #6b7280;
  --bg: #f3f4f6;
  --bg-card: #fff;
  --sidebar-w: 240px;
  --mobilebar-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ===== 로그인 ===== */
.login-body {
  background: linear-gradient(135deg, #1e3a8a 0%, #312e81 100%);
  min-height: 100vh;
  min-height: 100dvh;
}
.login-wrap {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-box {
  background: #fff; border-radius: 10px;
  padding: clamp(28px, 5vw, 40px) clamp(24px, 4vw, 36px);
  width: 100%; max-width: 380px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.2);
}
.login-title {
  margin: 0 0 4px; font-size: clamp(20px, 4vw, 22px); color: var(--primary-dark); text-align: center;
}
.login-sub { margin: 0 0 26px; color: var(--muted); text-align: center; font-size: 14px; }
.login-foot { margin-top: 18px; text-align: center; font-size: 13px; }
.login-foot a { color: var(--muted); }
.login-foot a:hover { color: var(--primary); }

/* ===== 폼 ===== */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: #374151;
}
.form-control,
.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="email"],
.form-group input[type="url"],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 16px;             /* iOS 자동 확대 방지: 최소 16px */
  font-family: inherit;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus,
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30,58,138,0.12);
}
.form-group textarea { min-height: 100px; resize: vertical; }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }

/* ===== 버튼 ===== */
.btn {
  display: inline-block;
  padding: 9px 18px;
  border: 1px solid transparent; border-radius: 6px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: all 0.15s; background: #fff; color: #374151;
  text-align: center;
  min-height: 40px;
  line-height: 1.2;
}
.btn:hover { background: #f9fafb; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }
.btn-ghost { background: transparent; color: #374151; border-color: var(--border); }
.btn-ghost:hover { background: #f3f4f6; }
.btn-sm { padding: 6px 12px; font-size: 13px; min-height: 32px; }
.btn-block { display: block; width: 100%; }

/* ===== 알림 ===== */
.alert { padding: 10px 14px; border-radius: 6px; font-size: 14px; margin-bottom: 14px; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* ===== 레이아웃 ===== */
.admin-layout { display: flex; min-height: 100vh; min-height: 100dvh; }

/* 모바일 상단 바 (기본은 숨김) */
.admin-mobilebar {
  display: none;
  position: sticky; top: 0; z-index: 90;
  height: var(--mobilebar-h);
  background: var(--primary-dark); color: #fff;
  align-items: center; gap: 10px; padding: 0 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.admin-mobilebar-toggle {
  width: 40px; height: 40px; flex-shrink: 0;
  background: none; border: none; cursor: pointer;
  position: relative; padding: 0;
}
.admin-mobilebar-toggle .nav-toggle-bar {
  position: absolute; left: 9px; right: 9px; height: 2px;
  background: #fff; border-radius: 2px;
  transition: transform 0.25s, opacity 0.2s, top 0.25s;
}
.admin-mobilebar-toggle .nav-toggle-bar:nth-child(1) { top: 13px; }
.admin-mobilebar-toggle .nav-toggle-bar:nth-child(2) { top: 19px; }
.admin-mobilebar-toggle .nav-toggle-bar:nth-child(3) { top: 25px; }
.admin-mobilebar-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(1) { top: 19px; transform: rotate(45deg); }
.admin-mobilebar-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(2) { opacity: 0; }
.admin-mobilebar-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(3) { top: 19px; transform: rotate(-45deg); }
.admin-mobilebar-title { font-size: 15px; font-weight: 600; }

/* 백드롭 */
.admin-backdrop {
  display: none;
  position: fixed; inset: 0; z-index: 95;
  background: rgba(0,0,0,0.45);
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--primary-dark); color: #cbd5e1;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  flex-shrink: 0;
  z-index: 96;
}
.sidebar-brand { padding: 22px 20px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.brand-title { color: #fff; font-size: 16px; font-weight: 700; }
.brand-sub { font-size: 12px; color: #94a3b8; margin-top: 2px; }
.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.sidebar-nav a {
  display: block; padding: 13px 20px; color: #cbd5e1;
  font-size: 14px; border-left: 3px solid transparent;
  transition: all 0.15s;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-nav a.active {
  background: rgba(255,255,255,0.1); color: #fff;
  border-left-color: var(--accent); font-weight: 600;
}
.sidebar-foot {
  padding: 16px 20px calc(16px + var(--safe-bottom));
  border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-foot .me { font-size: 13px; color: #fff; margin-bottom: 10px; }
.sidebar-foot .btn-ghost { color: #cbd5e1; border-color: rgba(255,255,255,0.2); background: transparent; }
.sidebar-foot .btn-ghost:hover { background: rgba(255,255,255,0.08); color: #fff; }
.link-home {
  display: block; margin-top: 12px; font-size: 12px; color: #94a3b8; text-align: center;
}
.link-home:hover { color: #fff; }

.main {
  flex: 1; min-width: 0;
  padding: clamp(20px, 3vw, 28px) clamp(16px, 3vw, 32px);
}
.main-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  margin-bottom: 24px;
}
.main-head h2 { margin: 0; font-size: clamp(18px, 3vw, 22px); color: var(--primary-dark); }
.main-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== 카드 ===== */
.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px; margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; padding: 20px;
}
.stat-label { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--primary-dark); margin-bottom: 8px; }
.stat-link { font-size: 13px; color: var(--primary); }
.stat-link:hover { color: var(--primary-dark); text-decoration: underline; }

.panel {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; padding: clamp(18px, 3vw, 24px); margin-bottom: 20px;
}
.panel h3 {
  margin: 0 0 14px; font-size: 16px; color: var(--primary-dark);
  padding-bottom: 10px; border-bottom: 1px solid var(--border);
}
.panel .guide-list { margin: 0; padding-left: 18px; color: #374151; font-size: 14px; }
.panel .guide-list li { margin-bottom: 6px; }

/* ===== 테이블 ===== */
.table-wrap {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td {
  padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table th {
  background: #f9fafb; font-weight: 600; color: #374151; font-size: 13px;
  white-space: nowrap;
}
.table tbody tr:hover { background: #f9fafb; }
.table tbody tr:last-child td { border-bottom: none; }
.table .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.table .col-num { width: 60px; text-align: center; color: var(--muted); }
.table .col-actions { width: 160px; }
.table .truncate {
  max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* 상태 뱃지 */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 12px; font-weight: 600;
}
.badge-on { background: #d1fae5; color: #065f46; }
.badge-off { background: #fee2e2; color: #991b1b; }
.badge-required { background: #fef3c7; color: #92400e; }
.badge-optional { background: #dbeafe; color: #1e40af; }

/* ===== 모달 ===== */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.modal-dialog {
  position: relative; background: #fff; border-radius: 10px;
  width: calc(100% - 32px); max-width: 640px;
  max-height: 86vh; overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 17px; color: var(--primary-dark); }
.modal-close {
  background: none; border: none; font-size: 26px;
  cursor: pointer; color: var(--muted); line-height: 1;
  width: 36px; height: 36px;
}
.modal-close:hover { color: #1f2937; }
.modal-body { padding: clamp(16px, 3vw, 20px); }
.modal-foot {
  padding: 14px 18px calc(14px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap;
}

/* ===== 토스트 ===== */
.toast {
  position: fixed; top: 20px; right: 20px; z-index: 300;
  background: #1f2937; color: #fff;
  padding: 12px 18px; border-radius: 6px; font-size: 14px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.25);
  opacity: 0; transform: translateY(-8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  max-width: calc(100vw - 40px);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ===== 빈 상태 ===== */
.empty-state {
  padding: 40px 20px; text-align: center; color: var(--muted); font-size: 14px;
}

/* ============================================================
   반응형
   ============================================================ */

/* 좁은 데스크톱 ~ 큰 태블릿 */
@media (max-width: 1024px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
}

/* 태블릿/모바일: 사이드바를 오프캔버스로 전환 */
@media (max-width: 900px) {
  .admin-layout { flex-direction: column; }

  .admin-mobilebar { display: flex; }
  .admin-backdrop { display: block; }
  .admin-backdrop[hidden] { display: none; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 78%; max-width: 320px;
    height: 100vh; height: 100dvh;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,0.2);
    z-index: 100;
  }
  .sidebar.open { transform: translateX(0); }

  body.admin-nav-open { overflow: hidden; }

  .main { padding: 18px 16px; }
  .main-head { margin-bottom: 18px; }

  .form-row { grid-template-columns: 1fr; }

  /* 테이블: 가로 스크롤 가능 */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table { min-width: 720px; }
  .table .truncate { max-width: 200px; }
}

/* 모바일 (스마트폰) */
@media (max-width: 640px) {
  .cards { grid-template-columns: 1fr; }
  .stat-value { font-size: 24px; }

  .main-head h2 { width: 100%; }
  .main-head .actions { width: 100%; justify-content: stretch; }
  .main-head .actions .btn,
  .main-head .actions select { flex: 1 1 auto; }

  .modal-foot { justify-content: stretch; }
  .modal-foot .btn { flex: 1 1 auto; }

  .toast { left: 16px; right: 16px; top: 16px; }
}

/* 호버 비지원(터치) 기기 */
@media (hover: none) {
  .table tbody tr:hover { background: transparent; }
  .btn:hover { background: #fff; }
  .btn-primary:hover { background: var(--primary); }
  .btn-danger:hover { background: var(--danger); }
  .btn-ghost:hover { background: transparent; }
}

/* 비밀번호 변경 폼 보조 스타일 */
.form-hint {
  font-size: 12px; color: var(--muted); margin-top: 6px;
}
.form-actions {
  display: flex; gap: 8px; margin-top: 20px; padding-top: 16px;
  border-top: 1px solid var(--border);
}
.form-actions .btn { min-width: 100px; }

@media (max-width: 640px) {
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; }
}