/* ========== Base ========== */
:root{
  --bg:#f5f6f8;           /* 헤더 배경 */
  --page:#ffffff;         /* 페이지 배경 */
  --card:#ffffff;         /* 패널/카드 */
  --card-2:#f8f9fa;       /* 카드 내부 보조색 */
  --text:#1f2937;         /* 기본 글자색 */
  --muted:#6b7280;        /* 보조 글자색 */
  --border:#e5e7eb;       /* 경계선(라이트) */
  --primary:#2563eb;      /* 메인 파랑 */
  --primary-600:#1d4ed8;  /* hover 파랑 */
  --danger:#dc2626;
  --warn:#d97706;
  --success:#059669;
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  background:var(--page);
  color:var(--text);
  font:14px/1.6 system-ui,-apple-system,Segoe UI,Roboto,Noto Sans KR,Apple SD Gothic Neo,Helvetica,Arial,sans-serif;
}

/* ========== Header ========== */
.header{
  display:flex; align-items:center; justify-content:space-between;
  padding:12px 16px; background:var(--bg); border-bottom:1px solid var(--border);
}
.header .logo{ font-weight:700; letter-spacing:.2px; color:#fff; }
.header .nav{ display:flex; gap:8px; }
.header .nav a{
  color:#374151; text-decoration:none; padding:8px 10px; border-radius:8px;
}
.header .nav a:hover{ background:#eef2ff; }
.header .nav a.active{ background:var(--primary); color:#fff; }
.header .right{ display:flex; gap:10px; align-items:center; }
.header .right .user-badge{
  background:#eef2ff; color:#1e40af; padding:6px 10px; border-radius:999px; font-size:12px;
  border:1px solid #c7d2fe;
}

/* ========== Layout ========== */
/* ========== Layout (폭 제어) ========== */
/* 기본: 넓게 (계약관리와 동일 느낌) */
body{
  display:flex;
  flex-direction:column;
  min-height:100vh;
}

/* 기본: 와이드(계약관리 느낌) — 캡 1600px, 항상 중앙정렬 */
.main-wrap{
  width: 100%;            /* 화면 가로 꽉 채우고 */
  max-width: 1300px;      /* 1600px까지만 넓어지도록 캡 */
  align-self: center;     /* ← 플렉스 cross-axis 중앙 정렬의 핵심 */
  padding: 0 16px;
  margin: 24px 0;         /* auto 대신 0: align-self가 중앙을 책임짐 */
  flex: 1 0 auto;         /* 푸터 밀어내기 */
}

/* 표가 넓을 때 가로 스크롤 */
.panel{
  margin-bottom:24px;
  overflow-x:auto;
}

/* 페이지별 선택 제어용 유틸 (body 클래스) */
body.narrow .main-wrap{ max-width: 1200px; }  /* 대시보드/통계 등 */
body.full   .main-wrap{ max-width: 100%; }    /* 완전한 가로 풀폭이 필요할 때 */

h1{ margin:0 0 10px; font-size:22px; color:#111827; }
.sub{ color:var(--muted); margin-bottom:16px; }

/* ========== Panels / Cards ========== */
.panel, .dash-card, .card{
  background:var(--card);
  border:1px solid var(--border);
  border-radius:12px;
  padding:16px;
}
.card-row{ display:grid; grid-template-columns:repeat(4,1fr); gap:12px; }
.dash-card .tit{ color:var(--muted); font-size:12px; }
.dash-card .val{ font-size:20px; font-weight:700; margin-top:4px; color:#111827; }

/* ========== Forms ========== */
input[type=text], input[type=password], input[type=number], input[type=date], input[type=url],
select, textarea{
  width:100%; background:#fff; color:var(--text);
  border:1px solid var(--border); border-radius:8px; padding:10px 12px; outline:none;
}
textarea{ min-height:90px; resize:vertical; }
input:focus, select:focus, textarea:focus{
  border-color:var(--primary);
  box-shadow:0 0 0 3px rgba(37,99,235,.15);
}
.input-full{ width:100%; }
.form-desc{ color:var(--muted); font-size:12px; margin-top:6px; }

.form-grid-2{ display:grid; grid-template-columns:1fr 1fr; gap:12px; }
.form-grid-1{ display:grid; grid-template-columns:1fr; gap:12px; }
.field{ display:flex; flex-direction:column; gap:6px; }
.field .label{ font-size:12px; color:var(--muted); }

.section-title{ margin:8px 0 10px; color:#374151; font-weight:600; }

/* ========== Buttons ========== */
.btn{
  display:inline-block; padding:8px 12px; border-radius:8px;
  background:#ffffff; color:#374151; text-decoration:none; border:1px solid var(--border);
}
.btn:hover{ background:#f9fafb; }
.btn-primary{ background:var(--primary); border-color:var(--primary-600); color:#fff; }
.btn-primary:hover{ background:var(--primary-600); }
.btn-danger{ background:#fee2e2; border-color:#fecaca; color:#b91c1c; }
.btn-danger:hover{ background:#fecaca; }
.btn-ghost{ background:transparent; border-color:transparent; color:var(--muted); }
.sticky-actions{
  position:sticky; bottom:0; background:var(--card); border-top:1px solid var(--border);
  padding:10px; display:flex; gap:8px; justify-content:flex-end; border-radius:0 0 12px 12px;
}

/* ========== Tables ========== */
.table{ width:100%; border-collapse:separate; border-spacing:0; }
.table thead th{
  background:#f3f4f6; color:#374151; text-align:left; font-weight:600; font-size:12px;
  position:sticky; top:0; z-index:1; border-bottom:1px solid var(--border);
  padding:10px 12px;
}
.table tbody td{ border-bottom:1px solid var(--border); padding:10px 12px; color:#111827; line-height: 1.2; }
.table tr:hover td{ background:#f9fafb; }

/* ========== Badges ========== */
.badge{ display:inline-block; padding:4px 8px; border-radius:999px; font-size:12px; border:1px solid transparent; }
.badge.gray{ background:#f3f4f6; color:#374151; border-color:#e5e7eb; }
.badge.green{ background:rgba(16,185,129,.12); color:#047857; border-color:#a7f3d0; }
.badge.yellow{ background:rgba(245,158,11,.12); color:#92400e; border-color:#fde68a; }
.badge.red{ background:rgba(239,68,68,.12); color:#991b1b; border-color:#fecaca; }

/* ========== Gallery ========== */
.gallery{ display:grid; grid-template-columns:repeat(4,1fr); gap:12px; }
.gallery .tile{
  border:1px solid var(--border); border-radius:8px; overflow:hidden; background:#fff;
}
.gallery .tile img{ width:100%; height:160px; object-fit:cover; display:block; }
.gallery .tile .cap{ padding:6px 8px; font-size:12px; color:var(--muted); border-top:1px solid var(--border); }

/* ========== Filters ========== */
.filter-bar{ display:flex; gap:10px; align-items:end; flex-wrap:wrap; }
.filter-bar label{ display:block; color:var(--muted); font-size:12px; margin-bottom:6px; }

/* ========== Alerts ========== */
.alert{ padding:10px 12px; border-radius:8px; }
.alert-success{ background:#ecfdf5; border:1px solid #a7f3d0; color:#065f46; }
.alert-danger{ background:#fef2f2; border:1px solid #fecaca; color:#7f1d1d; }

/* ========== Responsive ========== */
@media (max-width: 1024px){
  .card-row{ grid-template-columns:repeat(2,1fr); }
  .form-grid-2{ grid-template-columns:1fr; }
  .gallery{ grid-template-columns:repeat(2,1fr); }
}
@media (max-width: 540px){
  .card-row{ grid-template-columns:1fr; }
  .gallery{ grid-template-columns:1fr; }
}

/* 대시보드 카드 간격 */
.card-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px; /* 카드 간격 */
  margin-bottom: 24px; /* 카드와 다음 섹션 사이 간격 */
}

/* 패널(표, 목록 등) 간격 */
.panel {
  margin-bottom: 24px; /* 패널과 다음 요소 사이 간격 */
}

/* 섹션 제목과 내용 간격 */
.section {
  margin-bottom: 32px; /* 섹션끼리 띄우기 */
}

/* 공통 필터 레이아웃(일/월 매출 공통) */
.filter-bar {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr)); /* 시작/종료/직원/버튼/여백 */
  gap: 12px;
  align-items: end;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 16px;
}
.filter-bar .field { display:flex; flex-direction:column; gap:6px; }
.filter-bar .field .label { font-size:12px; color:var(--muted); }

/* 브라우저 기본 month UI 제거 + 공통 높이/라운딩/테두리 */
input[type="month"]{
  background:#fff;
  color:var(--text);
  border:1px solid var(--border);
  border-radius:8px;
  padding:10px 12px;
  height:40px;
  line-height:20px;
  outline:none;
  appearance:none;
  -webkit-appearance:none;
  -moz-appearance:none;
}

/* focus 상태 */
input[type="month"]:focus{
  border-color:var(--primary);
  box-shadow:0 0 0 3px rgba(37,99,235,.15);
}

/* 캘린더 아이콘 정돈(크롬/사파리 계열) */
input[type="month"]::-webkit-calendar-picker-indicator{
  cursor:pointer;
  opacity:0.7;
  margin-right:2px;
}
input[type="month"]::-webkit-datetime-edit,
input[type="month"]::-webkit-datetime-edit-year-field,
input[type="month"]::-webkit-datetime-edit-month-field{
  padding:0 2px;   /* 내부 텍스트 간격 */
}

/* 라이트 테이블 hover 색(혹시 어두운 값이 남아있다면 덮어쓰기) */
.table tr:hover td{ background:#f9fafb; }

/* 버튼 높이 통일 */
.filter-bar .btn,
.filter-bar .btn-primary{
  height:40px; display:inline-flex; align-items:center; justify-content:center;
  padding:0 14px;
}

/* 좁은 화면 대응 */
@media (max-width: 820px){
  .filter-bar{ grid-template-columns:1fr 1fr; }
}

/* ====== 계약관리 필터 레이아웃 ====== */
.filter-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr)); /* 검색어, 상태, 담당자, 날짜기준, 시작일, 종료일 */
  gap: 12px;
  align-items: end;
}
.filter-actions {
  display:flex;
  align-items:center;
  gap:8px;
  margin-top:12px;            /* 필터 아래 버튼/합계 줄 */
  justify-content:flex-start; /* 왼쪽 정렬 */
}
.filter-actions .sum {
  margin-left:auto;           /* 합계를 오른쪽 끝으로 */
  color: var(--muted);
}

/* 버튼 그룹(보기/수정/삭제) 가로 정렬 */
.btn-group {
  display:inline-flex;
  gap:8px;
  flex-wrap:nowrap;
}
.btn-small { padding:6px 10px; border-radius:8px; font-size:13px; }

/* 표 중앙 정렬(헤더/바디) */
.table.center thead th,
.table.center tbody td {
  text-align:center;
  vertical-align:middle;
}

/* 회사 컬럼/값 한 줄 처리 (줄바꿈 방지 + 길면 … ) */
.nowrap {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 필터 입력 높이/버튼 높이 통일 */
.filter-grid input,
.filter-grid select,
.filter-actions .btn,
.filter-actions .btn-primary { height:40px; }

/* 반응형: 너비 부족하면 2줄로 자연 분리 */
@media (max-width: 1100px){
  .filter-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } /* 2줄 × 3칸 */
}
@media (max-width: 680px){
  .filter-grid { grid-template-columns: 1fr; }   /* 모바일 1열 */
  .filter-actions { flex-wrap:wrap; }
  .filter-actions .sum { margin-left:0; }
}

/* 페이지를 세로 플렉스 컨테이너로 */
html, body { height: 100%; }
body{
  display: flex;
  flex-direction: column;
  min-height: 100vh; /* 화면 높이 꽉 채우기 */
}

/* 본문은 남는 공간을 차지 */
.main-wrap{
  flex: 1 0 auto;   /* 콘텐츠가 짧아도 공간 늘려 푸터 밀어내기 */
}

/* 푸터를 항상 맨 아래로 */
.footer{
  margin-top: auto; /* 핵심 한 줄! */
}
