:root {
  --primary: #7C3AED;          /* 보라 메인 */
  --primary-dark: #6D28D9;
  --primary-soft: #F3EEFE;     /* 보라 연한 배경 */
  --bg: #F9FAFB;               /* 메인 영역 배경 */
  --bg-alt: #F3F4F6;
  --card: #FFFFFF;
  --border: #E5E7EB;
  --border-strong: #D1D5DB;
  --text: #111827;
  --text-sub: #6B7280;
  --text-mute: #9CA3AF;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.05);
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
}

* { font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, sans-serif; box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); }

.hidden { display: none !important; }

/* ===================== 어드민 레이아웃 ===================== */
.admin-layout {
  display: flex;
  min-height: 100vh;
  background: var(--bg);
}

/* ---------- 사이드바 ---------- */
.sidebar {
  width: 248px;
  min-width: 248px;
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 22px;
}
.brand-logo { width: 30px; height: 30px; object-fit: contain; }
.brand-text { font-size: 17px; font-weight: 800; color: var(--text); letter-spacing: -.2px; }

.sidebar-nav { flex: 1; }
.nav-section-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-mute);
  letter-spacing: .4px;
  padding: 8px 8px 6px;
  text-transform: none;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-sub);
  cursor: pointer;
  transition: background .15s, color .15s;
  text-decoration: none;
}
.nav-item i { width: 18px; text-align: center; font-size: 14px; }
.nav-item:hover { background: var(--bg-alt); color: var(--text); }
.nav-item.active { background: var(--primary); color: #fff; box-shadow: 0 2px 6px rgba(124,58,237,.28); }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 14px 8px 4px;
  margin-top: 12px;
}
.footer-mail { font-size: 12.5px; color: var(--text-sub); font-weight: 500; }
.footer-company { font-size: 11.5px; color: var(--text-mute); margin-top: 2px; }

/* ---------- 메인 영역 ---------- */
.main-area {
  flex: 1;
  min-width: 0;
  padding: 28px 32px 48px;
}
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 22px;
}
.page-title { font-size: 22px; font-weight: 800; color: var(--text); margin: 0; letter-spacing: -.3px; }
.page-desc { font-size: 13.5px; color: var(--text-sub); margin: 6px 0 0; }

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 1100px) {
  .content-grid { grid-template-columns: 1fr; }
}

/* ---------- 카드 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 22px 22px 24px;
}
.card-head { display: flex; align-items: center; margin-bottom: 14px; }
.card-head.mt-6 { margin-top: 26px; }
.card-head-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-head-title i { color: var(--primary); font-size: 13px; }

/* ---------- 타입 탭 ---------- */
.type-tabs { display: flex; gap: 10px; }
.type-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text-sub);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.type-btn i { font-size: 13px; }
.type-btn:hover { background: var(--bg-alt); }
.type-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 2px 6px rgba(124,58,237,.26);
}

/* ---------- 필드 ---------- */
.fields-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.field-group { display: flex; flex-direction: column; gap: 6px; }
.field-group.col-span-2 { grid-column: span 2; }
.field-group.col-span-1 { grid-column: span 1; }
/* 호환: app.js가 col-span-2 sm:col-span-1 을 줄 수 있어 보정 */
.field-group[class*="sm:col-span-1"] { grid-column: span 1; }
@media (max-width: 560px) {
  .fields-grid { grid-template-columns: 1fr; }
  .field-group.col-span-2,
  .field-group[class*="col-span-1"] { grid-column: span 1; }
}
.field-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-sub);
  display: flex;
  align-items: center;
  gap: 6px;
}
.field-input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.field-input::placeholder { color: var(--text-mute); }
.field-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124,58,237,.14);
}
.field-input.is-auto { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
select.field-input { appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%239CA3AF' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; padding-right: 30px;
}
.auto-badge {
  font-size: 10px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 1px 7px;
  border-radius: 10px;
}

.hint-box {
  margin-top: 16px;
  font-size: 12.5px;
  color: var(--text-sub);
  background: var(--bg-alt);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
}
.hint-box b { color: var(--text); }

/* ---------- 첨부 영역 ---------- */
.paste-zone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  text-align: center;
  padding: 28px 16px;
  cursor: pointer;
  color: var(--text-sub);
  font-size: 13px;
  transition: border-color .15s, background .15s;
}
.paste-zone:hover { border-color: var(--primary); background: var(--primary-soft); }
.paste-zone.border-blue-400 { border-color: var(--primary); }
.paste-zone.bg-blue-50 { background: var(--primary-soft); }
.paste-zone b { color: var(--text); }
.paste-icon { font-size: 28px; color: var(--primary); display: block; margin-bottom: 10px; }
.paste-sub { font-size: 11.5px; color: var(--text-mute); margin-top: 6px; }

.thumbs { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 14px; }
.thumbs:empty { margin-top: 0; }
.thumb { position: relative; }
.thumb img {
  width: 80px; height: 96px; object-fit: cover;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
}
.thumb-del {
  position: absolute; top: -8px; right: -8px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #EF4444; color: #fff; border: none; cursor: pointer;
  font-size: 13px; line-height: 1; display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow);
}
.thumb-del:hover { background: #DC2626; }
.thumb-no {
  position: absolute; bottom: 4px; left: 4px;
  background: rgba(17,24,39,.7); color: #fff;
  font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 8px;
}

/* ---------- 액션 버튼 ---------- */
.action-row { display: flex; gap: 10px; margin-top: 24px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 700;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all .15s;
}
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; flex: 1; box-shadow: 0 2px 6px rgba(124,58,237,.26); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-ghost { background: #fff; color: var(--text-sub); border-color: var(--border-strong); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-alt); }
.btn-success { background: #16A34A; color: #fff; box-shadow: 0 2px 6px rgba(22,163,74,.24); }
.btn-success:hover:not(:disabled) { background: #15803D; }

/* ---------- 안내 카드 ---------- */
.guide-card { position: sticky; top: 28px; }
.guide-list {
  margin: 0;
  padding-left: 18px;
  font-size: 12.8px;
  line-height: 1.9;
  color: var(--text-sub);
}
.guide-list b { color: var(--text); }
.alert {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  font-size: 12px;
  line-height: 1.6;
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  margin-top: 14px;
}
.alert i { margin-top: 2px; }
.alert-warn { background: #FEF9C3; color: #854D0E; }
.alert-warn i { color: #CA8A04; }
.alert-info { background: var(--primary-soft); color: var(--primary-dark); }
.alert-info i { color: var(--primary); }
.alert b { font-weight: 700; }

/* ---------- 미리보기 모달 ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(17,24,39,.55);
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0;
  overflow-y: auto;
}
.modal-inner { width: 100%; max-width: 880px; padding: 0 0 60px; }
.modal-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  box-shadow: var(--shadow);
}
.modal-title { font-size: 15px; font-weight: 800; color: var(--text); display: flex; align-items: center; gap: 8px; }
.modal-title i { color: var(--primary); }
.modal-actions { display: flex; gap: 10px; }
#preview-content {
  padding: 28px 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ===================== 내용증명 문서 (A4) — 보존 ===================== */
.doc-page {
  width: 794px;            /* A4 @ 96dpi */
  height: 1123px;          /* A4 고정 높이 (본문/납부방법) */
  background: #fff;
  padding: 56px 64px;
  box-sizing: border-box;
  color: #111;
  font-size: 14.5px;
  line-height: 1.8;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(0,0,0,.12);
}
.doc-page + .doc-page { margin-top: 24px; }

.doc-title {
  text-align: center;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 14px;
  margin-bottom: 36px;
  padding-bottom: 4px;
}
.doc-meta { margin-bottom: 4px; }
.doc-section-gap { height: 20px; }
.doc-p { margin: 10px 0; text-align: justify; }
.doc-list { margin: 4px 0 10px 6px; }
.doc-list li { list-style: none; margin: 3px 0; }
.doc-attach-title {
  font-weight: 700;
  margin: 6px 0;
}
.doc-center { text-align: center; }
.doc-right { text-align: right; }

.highlight { color: #c026d3; font-weight: 700; }

.stamp-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 40px;
  font-size: 16px;
  font-weight: 600;
}
.stamp-img { width: 70px; height: 70px; object-fit: contain; }

.contract-img-wrap { margin-top: 16px; text-align: center; }
.contract-img-wrap img {
  max-width: 100%;
  border: 1px solid #e5e7eb;
  margin-bottom: 12px;
}

/* 계약서 페이지: 이미지 1장당 1페이지, 높이는 이미지에 맞춰 가변 */
.contract-page {
  height: auto;             /* A4 고정 높이 해제 */
  min-height: 0;
  overflow: visible;
  padding: 40px 48px;
}
.contract-full-img {
  display: block;
  width: 100%;
  height: auto;
}

.bank-box {
  border: 1.5px solid #111;
  padding: 16px 20px;
  margin-top: 18px;
  line-height: 2.1;
}

/* 페이지 나눔 (인쇄/PDF) */
.page-break { page-break-before: always; }

/* 입력값 누락 표시 */
.empty-val { background: #fef08a; color: #92400e; padding: 0 4px; border-radius: 3px; }
