/* Universal 표 편집기 (/plan/edit). styles.css 변수를 재사용. */

:root {
  --pe-card-bg: #ffffff;
  --pe-card-shadow: 0 1px 3px rgba(15, 118, 110, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --pe-success: #16a34a;
  --pe-success-bg: #ecfdf5;
  --pe-warn: #d97706;
  --pe-bar-track: #e6efed;
  --pe-cell-filled: #ecfdf5;
  --pe-cell-empty: #f8faf9;
  --pe-subject-unselected: #f3f4f6;
  --pe-sticky-bg: #f7f9fb;
}

.plan-edit-shell {
  max-width: none;
  margin: 0;
  padding: 16px 0;
  font-size: 14px;
  line-height: 1.5;
}

.plan-edit-loading,
.plan-edit-error {
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
}

.plan-edit-error {
  color: var(--danger);
}

/* 헤더 */
.plan-edit-header {
  background: var(--pe-card-bg);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--pe-card-shadow);
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.header-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.header-title-row {
  justify-content: space-between;
}

.plan-edit-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
}

.plan-edit-logout {
  background: var(--pe-bar-track);
  color: var(--muted);
  min-height: 32px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 600;
}

.header-meta-row label,
.header-cycle-row label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.header-meta-row select,
.header-cycle-row select {
  width: auto;
  min-width: 200px;
}

.header-cycle-row button {
  min-height: 34px;
  font-size: 13px;
}

/* 완성률 */
.plan-edit-completion {
  background: var(--pe-card-bg);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--pe-card-shadow);
  margin-bottom: 12px;
}

.completion-overall {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 12px;
}

.completion-overall .pct {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}

.completion-overall .label {
  font-size: 14px;
  color: var(--muted);
}

.completion-sections {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
}

.completion-section-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.completion-section-item .section-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.completion-section-item .section-bar {
  flex: 0 0 50px;
  height: 6px;
  background: var(--pe-bar-track);
  border-radius: 3px;
  overflow: hidden;
}

.completion-section-item .section-bar-fill {
  height: 100%;
  background: var(--accent);
  transition: width .2s ease;
}

.completion-section-item .section-pct {
  flex: 0 0 32px;
  text-align: right;
  font-weight: 600;
  color: var(--ink);
}

/* 새 사이클 폼 */
.plan-edit-cycle-form {
  background: var(--pe-card-bg);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--pe-card-shadow);
  margin-bottom: 12px;
}

.plan-edit-cycle-form h2 {
  margin: 0 0 12px;
  font-size: 16px;
}

.plan-edit-cycle-form label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  justify-content: flex-end;
}

/* 헤더 사이클 row 버튼 다수 — 자동 줄바꿈 허용 */
.header-cycle-row {
  flex-wrap: wrap;
  gap: 6px;
}
.header-cycle-row button,
.header-cycle-row select {
  flex: 0 0 auto;
}

/* 폼 도움말 텍스트 */
.form-hint {
  color: var(--pe-muted-text);
  font-size: 0.85rem;
  margin: 6px 0 12px;
}

/* 캘린더 시험 일정 선택 리스트 */
.calendar-pick-search {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.calendar-pick-search label {
  flex: 1 1 240px;
}
.calendar-pick-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  margin-bottom: 8px;
}
.calendar-pick-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  align-items: center;
  padding: 10px 12px;
  background: var(--pe-card-bg);
  border: 1px solid var(--pe-card-border, #e0e6eb);
  border-radius: 8px;
}
.calendar-pick-item .pick-checkbox {
  grid-row: 1 / span 2;
  width: 18px;
  height: 18px;
  cursor: pointer;
}
.calendar-pick-item .pick-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
}
.calendar-pick-item .pick-title {
  font-weight: 600;
}
.calendar-pick-item .pick-date {
  font-size: 0.85rem;
  color: var(--pe-muted-text);
}

/* primary 버튼 — form-actions 안에서 강조용 */
button.primary,
.calendar-pick-apply.primary {
  background: var(--pe-accent, #2563eb);
  color: #fff;
  border-color: var(--pe-accent, #2563eb);
}

/* 섹션 패널 */
.plan-edit-panels {
  display: block;
}

.plan-edit-panel {
  background: var(--pe-card-bg);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--pe-card-shadow);
  margin-bottom: 12px;
}

.panel-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 8px;
  flex-wrap: wrap;
}

.panel-title {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
}

.block-title {
  margin: 16px 0 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

/* 시간·장소 블록 제목 행 — 자주 가는 장소 추가 UI와 같은 줄에 */
.block-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 16px 0 8px;
}
.block-title-row .block-title {
  margin: 0;
}

/* 자주 가는 장소 — 추가 UI */
.fav-location-add {
  display: flex;
  gap: 6px;
  align-items: center;
  flex: 0 1 auto;
}
.fav-location-add input[type="text"] {
  width: 200px;
  max-width: 40vw;
  padding: 4px 8px;
  font-size: 13px;
}

/* 자주 가는 장소 칩 리스트 */
.fav-location-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
  min-height: 4px;
}
.fav-location-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border: 1px solid var(--pe-card-border, #d0d6dc);
  border-radius: 999px;
  background: var(--pe-card-bg);
  font-size: 12px;
}
.fav-location-chip .fav-location-del {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
}
.fav-location-chip .fav-location-del:hover {
  color: var(--danger, #c0392b);
}

/* 표 안 자주 가는 장소 드롭다운 */
.fav-location-cell {
  padding: 2px;
}
.fav-location-select {
  width: 100%;
  font-size: 12px;
  padding: 4px 6px;
}

.schedule-block,
.resolution-block,
.habits-block,
.reflections-block {
  margin-bottom: 8px;
}

/* 표 공통 */
table.plan-grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: fixed;
}

table.plan-grid th,
table.plan-grid td {
  border: 1px solid var(--line);
  padding: 0;
  vertical-align: middle;
}

table.plan-grid th {
  background: var(--pe-sticky-bg);
  font-weight: 600;
  color: var(--muted);
  padding: 6px 8px;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 1;
}

/* 인라인 셀 input */
table.plan-grid input,
table.plan-grid textarea {
  width: 100%;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 6px 8px;
  font-size: 13px;
}

table.plan-grid input:focus,
table.plan-grid textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: #fff;
}

table.plan-grid .cell-filled {
  background: var(--pe-cell-filled);
}

table.plan-grid .cell-empty {
  background: var(--pe-cell-empty);
}

/* 과목 표 — 채워진 값은 옅은 초록, 미선택 과목은 회색 */
.subject-row-unselected {
  opacity: 0.55;
  background: var(--pe-subject-unselected);
}

.subject-row-unselected input,
.subject-row-unselected textarea {
  text-decoration: line-through;
  color: var(--muted);
}

.subject-row td:first-child,
.subject-row th:first-child {
  text-align: center;
}

.subject-checkbox-cell {
  text-align: center;
  padding: 6px 8px;
}

.subject-checkbox-cell input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.subject-name-cell {
  font-weight: 600;
  color: var(--ink);
  padding: 6px 8px;
  text-align: center;
  vertical-align: middle;
}

.subject-row .subject-admin-controls {
  text-align: right;
  padding: 4px 6px;
  white-space: nowrap;
}

.subject-row .subject-admin-controls button {
  min-height: 28px;
  padding: 0 8px;
  font-size: 11px;
  margin-left: 2px;
}

/* 가로 스크롤 래퍼 (과목 표가 폭 넓음) */
.subjects-scroll {
  overflow-x: auto;
  margin-bottom: 8px;
}

.subjects-scroll table.plan-grid {
  min-width: 1100px;
}

/* 기대 textarea 큰 폼 */
.expectations-container textarea {
  width: 100%;
  margin-bottom: 8px;
}

/* 시간/생활 — 7행 표 2개 병렬 */
.schedule-grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 900px) {
  .schedule-grid-2col { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
}

/* 토스트 */
.plan-edit-toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  z-index: 100;
  max-width: 80vw;
}

.plan-edit-toast.error {
  background: var(--danger);
}

.plan-edit-toast.success {
  background: var(--pe-success);
}

/* Role별 토글 — body[data-role="child"]에서는 .admin-only 숨김 */
body[data-role="child"] .admin-only {
  display: none !important;
}

body[data-role="admin"] .child-only {
  display: none !important;
}

/* iframe 임베드 시 (관리자 대시보드 자녀별 탭 안) — 중복 UI 숨김.
   자녀별 탭 버튼이 자녀명을 표시하므로 페이지 제목·로그아웃·자녀 셀렉터 불필요.
   cycle row, 완성률, 세로 나열된 섹션 패널은 그대로 표시. */
body[data-embedded="true"] .header-title-row h1,
body[data-embedded="true"] .plan-edit-logout,
body[data-embedded="true"] .header-meta-row.admin-only {
  display: none !important;
}

/* 작은 화면 대응 */
@media (max-width: 720px) {
  .plan-edit-shell { padding: 8px; }
  .plan-edit-header,
  .plan-edit-completion,
  .plan-edit-panel,
  .plan-edit-cycle-form { padding: 12px; border-radius: 10px; }
  .plan-edit-header h1 { font-size: 18px; }
  .header-meta-row select,
  .header-cycle-row select { min-width: 140px; }
}

/* ===================== 인쇄 / PDF 출력 ===================== */
@media print {
  @page { size: A4; margin: 14mm; }

  /* 숨김: 편집용 UI 전체 */
  #plan-edit-loading,
  #plan-edit-error,
  .plan-edit-header button,
  #plan-edit-completion,
  #plan-edit-cycle-form,
  #plan-edit-import-past-form,
  #plan-edit-calendar-pick,
  #plan-edit-toast,
  .slot-add,
  .fav-location-add,
  .subject-admin-actions,
  .completion-sections,
  .header-meta-row,
  .header-cycle-row { display: none !important; }

  /* 셸 레이아웃 리셋 */
  .plan-edit-shell { max-width: none; margin: 0; padding: 0; }
  .plan-edit-header { border: none; padding: 0 0 6px 0; }
  .plan-edit-panels { padding: 0; gap: 0; }

  /* 패널: 페이지 잘림 정책 */
  .plan-edit-panel {
    page-break-inside: avoid;
    margin-bottom: 0;
    padding: 8px 0;
    border: none;
    box-shadow: none;
  }

  /* 표: 행 중간 잘림 방지 */
  table { page-break-inside: auto; }
  tr { page-break-inside: avoid; }
  thead { display: table-header-group; }

  /* 입력칸 → 종이 텍스트처럼 */
  input, textarea {
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    padding: 2px 0 !important;
    -webkit-appearance: none;
    appearance: none;
    outline: none;
  }
  /* 빈 입력칸 숨김 */
  .cell-empty { display: none; }

  /* 컬러 인쇄 강제 */
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
