*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1e6abf;
  --primary-dark: #155299;
  --accent: #e8f0fb;
  --success: #2e7d32;
  --danger: #c62828;
  --border: #d0d7e2;
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1a1a2e;
  --muted: #6b7280;
  --radius: 10px;
  --shadow: 0 2px 8px rgba(0,0,0,0.10);
}

body {
  font-family: 'Pretendard', 'Noto Sans KR', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }

/* ── 공통 버튼 ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s, opacity 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: #fff; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--accent); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.85; }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-icon { padding: 6px 10px; }

/* ── 카드 ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* ── 폼 요소 ── */
label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 4px; }
input[type="number"],
input[type="text"],
select {
  width: 100%;
  padding: 7px 10px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: #fff;
  transition: border-color 0.15s;
}
input:focus, select:focus { outline: none; border-color: var(--primary); }
input.narrow { width: 80px; }
input.medium { width: 120px; }

/* ── 섹션 제목 ── */
.section-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 14px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--accent);
}
.subsection-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin: 16px 0 10px;
}

/* ── 점수 뱃지 ── */
.score-badge {
  display: inline-block;
  background: var(--accent);
  color: var(--primary-dark);
  border-radius: 20px;
  padding: 2px 12px;
  font-size: 13px;
  font-weight: 700;
}
.score-badge.green { background: #e8f5e9; color: var(--success); }

/* ── 행 레이아웃 ── */
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row .field { flex: 1; min-width: 80px; }

/* ── 동적 행 테이블 ── */
.dynamic-table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.dynamic-table th {
  background: var(--accent);
  color: var(--primary-dark);
  font-size: 12px;
  padding: 6px 8px;
  text-align: center;
  border: 1px solid var(--border);
}
.dynamic-table td {
  padding: 5px 6px;
  border: 1px solid var(--border);
  vertical-align: middle;
  text-align: center;
}
.dynamic-table td input, .dynamic-table td select {
  margin: 0;
  text-align: center;
}
.dynamic-table .score-cell {
  text-align: center;
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
  min-width: 60px;
}

/* ── 커스텀 날짜 선택기 ── */
.custom-date-picker {
  position: absolute;
  z-index: 2000;
  width: 280px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.16);
  padding: 12px;
}
.cdp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 10px;
}
.cdp-title-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
}
.cdp-field {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.cdp-field input {
  width: 64px;
  padding: 6px 8px;
  text-align: center;
  appearance: textfield;
  -moz-appearance: textfield;
}
.cdp-field input::-webkit-outer-spin-button,
.cdp-field input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.cdp-field .cdp-month {
  width: 48px;
}
.cdp-field span {
  font-size: 13px;
  color: var(--text);
}
.cdp-nav,
.cdp-action,
.cdp-day {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
}
.cdp-nav {
  width: 32px;
  height: 32px;
  font-size: 16px;
  color: var(--primary-dark);
}
.cdp-weekdays,
.cdp-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cdp-weekdays {
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}
.cdp-day {
  height: 34px;
  font-size: 13px;
  color: var(--text);
}
.cdp-day:hover:not(:disabled) {
  background: var(--accent);
}
.cdp-day.is-muted {
  color: #a0a8b4;
}
.cdp-day.is-selected {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 700;
}
.cdp-day.is-sun {
  color: var(--danger);
}
.cdp-day.is-sat {
  color: var(--primary-dark);
}
.cdp-day.is-selected.is-sun,
.cdp-day.is-selected.is-sat {
  color: #fff;
}
.cdp-day:disabled {
  cursor: default;
  opacity: 0.35;
}
.cdp-footer {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 10px;
}
.cdp-action {
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text);
}

/* ── 하단 고정 요약 바 ── */
#score-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--primary-dark);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 10px 20px;
  z-index: 100;
  font-size: 14px;
  flex-wrap: wrap;
}
#score-bar .bar-item { display: flex; flex-direction: column; align-items: center; gap: 2px; }
#score-bar .bar-label { font-size: 11px; opacity: 0.75; }
#score-bar .bar-score { font-size: 16px; font-weight: 800; }
#score-bar .bar-total { font-size: 20px; font-weight: 900; color: #ffd54f; }
#score-bar .bar-divider { width: 1px; height: 36px; background: rgba(255,255,255,0.25); }

/* ── 탭 ── */
.tab-list {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  flex-wrap: wrap;
  position: sticky;
  top: 53px; /* page-header 높이 */
  z-index: 40;
  background: var(--bg);
  padding: 6px 0 0;
}
.tab-btn {
  padding: 9px 20px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── 헤더 ── */
.page-header {
  background: var(--card);
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 50;
}
.page-header h1 { font-size: 17px; font-weight: 800; color: var(--primary-dark); }
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── 메인 페이지 ── */
.main-wrap { max-width: 900px; margin: 0 auto; padding: 30px 20px 60px; }
.hero { text-align: center; margin-bottom: 32px; }
.hero h1 { font-size: 26px; font-weight: 900; color: var(--primary-dark); margin-bottom: 6px; }
.hero p { color: var(--muted); }

.user-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.user-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.user-card:hover { border-color: var(--primary); box-shadow: 0 4px 14px rgba(30,106,191,0.15); }
.user-avatar {
  width: 52px; height: 52px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 800; color: var(--primary);
}
.user-name { font-weight: 700; font-size: 15px; }
.user-updated { font-size: 12px; color: var(--muted); }
.user-card-actions { display: flex; gap: 6px; margin-top: 4px; }

.import-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s;
}
.import-area:hover { border-color: var(--primary); }

/* ── 계산기 페이지 ── */
.calc-wrap { max-width: 860px; margin: 0 auto; padding: 20px 16px 100px; }

.sub-score {
  float: right;
  font-size: 13px;
  color: var(--primary);
  font-weight: 700;
  background: var(--accent);
  border-radius: 20px;
  padding: 1px 10px;
}

.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ── 모달 ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal-box {
  background: #fff;
  border-radius: var(--radius);
  padding: 28px 24px;
  min-width: 300px;
  max-width: 440px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}
.modal-title { font-size: 17px; font-weight: 800; margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* ── 반응형 ── */
@media (max-width: 600px) {
  .tab-btn { padding: 8px 12px; font-size: 13px; }
  #score-bar { gap: 12px; }
  #score-bar .bar-total { font-size: 18px; }
}

/* ── 날짜 입력 스피너 제거 ── */
.date-year-input::-webkit-outer-spin-button,
.date-year-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.date-year-input { -moz-appearance: textfield; appearance: textfield; }

/* ── 연도 이동 버튼 ── */
.year-nav-btn {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 4px;
  padding: 3px 6px;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  color: var(--muted);
  transition: all 0.12s;
  flex-shrink: 0;
}
.year-nav-btn:hover { background: var(--accent); border-color: var(--primary); color: var(--primary); }

/* ── 선택가산점 섹션 헤더 (체크박스 포함) ── */
.sel-section-header {
  display: flex !important;
  align-items: center;
  gap: 8px;
  margin: 16px 0 10px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}
.sel-section-header .sel-badge {
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}
.sel-enable-cb {
  width: 16px !important;
  height: 16px !important;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--primary);
}

/* ── 선택가산점 섹션 비활성 상태 ── */
.sel-section-body.inactive {
  display: none;
}

/* ── 차출예상 탭 ── */
#proj-layout {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}
#proj-summary-panel {
  flex: 0 0 340px;
  position: sticky;
  top: 100px;
}
#proj-table-panel { flex: 1; }

.proj-summary-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.proj-summary-table th { text-align: left; padding: 4px 6px; color: var(--muted); font-weight: 500; }
.proj-summary-table td { text-align: right; padding: 4px 6px; font-weight: 700; color: var(--primary); }
.proj-summary-table .ps-max { color: var(--muted); font-weight: 400; font-size: 11px; }
.proj-summary-table .ps-indent th { padding-left: 18px; }
.proj-summary-table .ps-indent2 th { padding-left: 32px; }
.proj-summary-table .ps-total th,
.proj-summary-table .ps-total td { font-size: 15px; font-weight: 900; color: var(--primary-dark); border-top: 2px solid var(--border); padding-top: 8px; }
.proj-summary-legend {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.proj-summary-legend-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 8px;
}
.proj-summary-legend-list {
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 10px;
  font-size: 12px;
  color: var(--muted);
}
.proj-summary-legend-list .legend-item {
  display: flex;
  align-items: baseline;
  gap: 4px;
  line-height: 1.4;
}
.proj-summary-legend-list dt {
  color: var(--primary-dark);
  font-weight: 700;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}
.proj-summary-legend-list dd {
  margin: 0;
}
.proj-current-caps {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.proj-current-caps-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 8px;
}
.proj-current-caps-body {
  min-height: 22px;
  color: var(--muted);
}

.proj-year-table th { font-size: 11px; padding: 4px 5px; }
.proj-year-table td { padding: 3px 4px; }
.proj-year-table input[type="number"] { padding: 4px 5px; font-size: 12px; }
.proj-year-table input[type="number"]:disabled {
  background: #f1f3f5;
  color: #adb5bd;
  cursor: not-allowed;
}
.proj-year-table select { padding: 4px 5px; font-size: 12px; }
tr.proj-rule-change td { border-top: 2px solid #c62828; }
.pj-pos { color: var(--success) !important; }
.pj-neg { color: var(--danger) !important; }
.pj-r-caps {
  min-width: 180px;
  text-align: left !important;
  white-space: normal !important;
}
.proj-cap-badge {
  display: inline-block;
  margin: 2px 4px 2px 0;
  padding: 2px 8px;
  border-radius: 999px;
  background: #fff4e5;
  color: #a15c00;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.4;
}

.proj-summary-table tr { cursor: help; }
.proj-summary-table tbody tr:hover th,
.proj-summary-table tbody tr:hover td,
.proj-summary-table tbody tr:focus-visible th,
.proj-summary-table tbody tr:focus-visible td { background: #f4f8ff; }
.proj-summary-table tbody tr:focus { outline: none; }
.proj-summary-table tbody tr:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.proj-tooltip {
  position: fixed;
  z-index: 9999;
  display: none;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 6px 20px rgba(0,0,0,0.14);
  border-radius: 8px;
  padding: 10px 12px;
  min-width: 240px;
  max-width: 360px;
  font-size: 12px;
  pointer-events: none;
}
.proj-tooltip.show { display: block; }
.proj-tooltip .pt-title {
  font-weight: 800;
  color: var(--primary-dark);
  font-size: 13px;
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.proj-tooltip table { width: 100%; border-collapse: collapse; }
.proj-tooltip th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  padding: 3px 8px 3px 0;
  white-space: nowrap;
}
.proj-tooltip td {
  text-align: right;
  font-weight: 700;
  color: var(--primary);
  padding: 3px 0;
}
.proj-tooltip td.pt-max {
  color: var(--muted);
  font-weight: 400;
  font-size: 11px;
  padding-left: 6px;
  white-space: nowrap;
}
.proj-tooltip td.pt-formula {
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
  padding-right: 6px;
  white-space: nowrap;
}
.proj-tooltip td.pt-info {
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
}
.proj-tooltip tr.pt-sum th,
.proj-tooltip tr.pt-sum td {
  border-top: 1px solid var(--border);
  padding-top: 6px;
  color: var(--primary-dark);
}

@media (max-width: 700px) {
  #proj-layout { flex-direction: column; }
  #proj-summary-panel { flex: none; width: 100%; position: static; }
}

/* ── 중복 경고 ── */
.overlap-warning {
  display: none;
  background: #fff3e0;
  border: 1.5px solid #ff9800;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  color: #e65100;
  margin-top: 6px;
}
.overlap-warning.visible { display: block; }
