/* 기본 설정 */
:root {
  --header-height: 70px;
  /* 컨테이너 너비 (데스크톱) */
  --max-width: 1400px; 
  --card-background: #1e293b;
  --post-padding: 2.5rem;
  --accent-color: #60a5fa;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --border-color: #2d3748;
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.3);
}

.post-wrapper {
  margin-top: var(--header-height);
  min-height: calc(100vh - var(--header-height));
  background: #0f172a;
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1rem;
}

.post-detail {
  background: var(--card-background);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  margin: 2rem auto;
  overflow: hidden;
}

.post-header {
  padding: var(--post-padding);
  border-bottom: 1px solid var(--border-color);
}

.post-meta {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.post-category {
  background: var(--accent-color);
  color: white;
  padding: 0.4rem 1rem;
  border-radius: 20px;
  font-weight: 500;
  font-size: 0.9rem;
}

.post-views {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* 데스크톱 제목 폰트 크기(원본) */
.post-title {
  font-size: 1.5rem;
  line-height: 1.3;
  margin: 1.5rem 0 1rem;
  color: var(--text-primary);
  font-weight: 600;
  word-break: keep-all;
}

.post-description {
  font-size: 1.2rem;
  line-height: 1.6;
  color: var(--text-secondary);
  margin: 0;
}

.post-content {
  padding: var(--post-padding);
  border: 1px solid var(--border-color); /* 테두리 색상은 var(--border-color) 사용 */
  border-radius: 12px; /* 모서리를 12px 반경으로 둥글게 처리 */
}


.markdown-body {
  font-size: 1.1rem;
  line-height: 1.8;
  color: var(--text-primary);
}

/* 이미지 최대 너비 제한 - 너무 크게 늘어나지 않도록 */
.markdown-body img {
  display: block;
  margin: 2rem auto;
  max-width: 700px;
  width: 100%;
  height: auto;
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  cursor: zoom-in;
  transition: transform 0.3s ease;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin-top: 2em;
  margin-bottom: 1em;
  font-weight: 500;
  line-height: 1.3;
  color: var(--text-primary);
}

.markdown-body h1 { font-size: 2rem; }
.markdown-body h2 { font-size: 1.6rem; }
.markdown-body h3 { font-size: 1.4rem; }
.markdown-body h4 { font-size: 1.2rem; }
.markdown-body h5 { font-size: 1.1rem; }
.markdown-body h6 { font-size: 1rem; }

.markdown-body p {
  margin: 1.5rem 0;
  color: var(--text-primary);
}

.markdown-body a {
  color: var(--accent-color);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}

.markdown-body a:hover {
  border-bottom-color: var(--accent-color);
}

.markdown-body pre {
  background: #2a3849;
  padding: 1.5rem;
  border-radius: 12px;
  overflow-x: auto;
  margin: 1.5rem 0;
}

.markdown-body code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.9em;
  padding: 0.2em 0.4em;
  background: #2a3849;
  border-radius: 4px;
  color: #e2e8f0;
}

.markdown-body pre code {
  padding: 0;
  background: none;
  font-size: 0.95em;
}

.markdown-body blockquote {
  margin: 2rem 0;
  padding: 1.5rem 2rem;
  border-left: 4px solid var(--accent-color);
  background: #2a3849;
  border-radius: 0 12px 12px 0;
  color: var(--text-secondary);
  font-style: italic;
}

.related-posts {
  background: #0f172a;
  padding: 4rem 0;
}

.related-posts h2 {
  text-align: center;
  font-size: 1.8rem;
  margin-bottom: 2.5rem;
  color: var(--text-primary);
  font-weight: 500;
}

.related-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2rem;
  list-style: none;
  padding: 0;
}

.related-post {
  background: var(--card-background);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  transition: transform 0.3s, box-shadow 0.3s;
  animation: fadeIn 0.6s ease-out backwards;
}

.related-post:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow-lg);
}

.related-post:nth-child(1) { animation-delay: 0.1s; }
.related-post:nth-child(2) { animation-delay: 0.2s; }
.related-post:nth-child(3) { animation-delay: 0.3s; }
.related-post:nth-child(4) { animation-delay: 0.4s; }
.related-post:nth-child(5) { animation-delay: 0.5s; }
.related-post:nth-child(6) { animation-delay: 0.6s; }

.related-image {
  width: 100%;
  height: 220px;
  object-fit: cover;
  border-radius: 16px 16px 0 0;
}

.related-content {
  padding: 1.5rem;
}

.related-title {
  font-size: 1.1rem;
  font-weight: 500;
  margin: 0 0 1rem;
  line-height: 1.4;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.related-date {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.post-navigation {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2rem;
  padding: var(--post-padding);
  border-top: 1px solid var(--border-color);
}

.prev-post,
.next-post {
  padding: 1.5rem;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  text-decoration: none;
  transition: all 0.3s ease;
}

.prev-post:hover,
.next-post:hover {
  border-color: var(--accent-color);
  background: #2a3849;
}

.nav-label {
  display: block;
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.nav-title {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.post-files {
  padding: 2rem;
  border-top: 1px solid var(--border-color);
  background: var(--card-background);
}

.post-files h2 {
  font-size: 1.2rem;
  color: var(--text-primary);
  margin-bottom: 1rem;
  font-weight: 500;
}

.file-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.file-item {
  margin: 0.5rem 0;
}

.file-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: #2a3849;
  border-radius: 8px;
  color: var(--text-primary);
  text-decoration: none;
  transition: all 0.2s ease;
}

.file-link:hover {
  background: var(--accent-color);
  color: white;
}

.file-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

.admin-actions {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding: 10px;
}

.delete-form {
  display: inline-block;
}

.delete-button {
  display: flex;
  align-items: center;
  gap: 5px;
  background-color: #ff4d4d;
  color: white;
  border: none;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: bold;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.3s ease, transform 0.2s;
}

.delete-button:hover {
  background-color: #e60000;
  transform: scale(1.05);
}

.delete-button svg {
  width: 16px;
  height: 16px;
  fill: white;
}

.delete-button span {
  white-space: nowrap;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 데스크톱 ~ 태블릿 이하 (1024px) */
@media (max-width: 1024px) {
  .container {
    max-width: 900px;
  }
  .related-grid {
    gap: 1.5rem;
  }
}

/* 태블릿 이하 (768px) */
@media (max-width: 768px) {
  :root {
    --post-padding: 0.75rem;
  }

  .container {
    max-width: 100% !important;
    margin: 0 !important;
    /* 좌우 여백을 더 줄여 넓게 보이도록 */
    padding: 0 0.3rem !important; 
  }
  .post-detail {
    margin: 0;
    border-radius: 0;
    width: 100%;
  }
  /* 모바일에서 제목 더 작게 */
  .post-title {
    font-size: 1.3rem; /* 기존 1.6rem에서 추가 축소 */
    font-weight: 600;
  }
  .post-description {
    font-size: 1.1rem;
  }
  .post-navigation {
    grid-template-columns: 1fr;
    padding: 0.75rem 0.5rem;
  }
  .related-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 1rem;
  }
  .markdown-body {
    font-size: 1rem;
    line-height: 1.8;
    padding: 0;
  }
  .markdown-body h1 {
    font-size: 1.5rem; /* 조금 더 줄임 */
  }
  .markdown-body h2 {
    font-size: 1.3rem;
  }
  .related-posts h2 {
    font-size: 1.6rem;
    margin-bottom: 2rem;
  }
  .related-image {
    height: 180px;
  }
  .post-content {
    padding: 0.5rem 0.3rem;
  }
  .post-header {
    padding: 0.75rem 0.5rem;
  }
  .markdown-body img {
    /* 음수 마진 제거, 기본 여백 */
    margin: 1rem auto !important;
  }
}

/* 모바일 이하 (480px) */
@media (max-width: 480px) {
  :root {
    --post-padding: 0.5rem;
  }
  .post-meta {
    flex-wrap: wrap;
    gap: 0.8rem;
  }
  .related-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px;
  }
  .related-content {
    padding: 0.8rem 0.5rem;
  }
  .related-title {
    font-size: 1rem;
    margin-bottom: 0.5rem;
  }
  .related-image {
    height: 140px;
  }
  .post-header {
    padding: 0.5rem 0.3rem;
  }
  .post-content {
    padding: 0.3rem 0.2rem;
  }
  /* 초소형 화면에서 제목을 더 작게 */
  .post-title {
    font-size: 1.2rem; 
    margin: 0.8rem 0 0.6rem;
  }
  .post-description {
    font-size: 0.95rem;
  }
  .markdown-body {
    font-size: 0.95rem;
  }
  .markdown-body img {
    margin: 0.8rem auto !important;
  }
  .markdown-body pre {
    padding: 0.8rem 0.3rem;
    margin: 1rem 0;
    width: 100%;
  }
  .markdown-body blockquote {
    padding: 0.8rem 0.5rem;
    margin: 1rem 0;
    width: 100%;
  }
  .post-files {
    padding: 0.5rem 0.3rem;
  }
  .post-navigation {
    padding: 0.5rem 0.3rem;
    gap: 0.8rem;
  }
  .prev-post,
  .next-post {
    padding: 0.8rem 0.5rem;
  }
  .related-posts {
    padding: 1.5rem 0 1rem;
  }
  .file-link {
    padding: 0.6rem 0.5rem;
  }
}

/* 관리자 버튼 컨테이너 스타일 */
.admin-actions {
    display: flex;
    gap: 10px;
    margin: 20px 0;
    justify-content: flex-end; /* 우측 정렬 */
}

/* 모든 버튼에 공통으로 적용되는 스타일 */
.admin-actions .write-button,
.admin-actions .edit-button,
.admin-actions .delete-button {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    border-radius: 4px;
    border: none;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.3s ease;
}

/* 글쓰기 버튼 스타일 */
.admin-actions .write-button {
    background-color: #27ae60; /* 녹색 계열 */
    color: white;
}

.admin-actions .write-button:hover {
    background-color: #219653;
}

/* 수정 버튼 스타일 */
.admin-actions .edit-button {
    background-color: #3498db; /* 파란색 계열 */
    color: white;
}

.admin-actions .edit-button:hover {
    background-color: #2980b9;
}

/* 삭제 버튼 스타일 */
.admin-actions .delete-button {
    background-color: #e74c3c; /* 빨간색 계열 */
    color: white;
}

.admin-actions .delete-button:hover {
    background-color: #c0392b;
}

/* 아이콘 스타일 */
.admin-actions svg {
    width: 18px;
    height: 18px;
    margin-right: 5px;
}

/* 반응형 스타일 */
@media (max-width: 768px) {
    .admin-actions {
        flex-direction: column;
        align-items: flex-end;
    }
    
    .admin-actions .write-button,
    .admin-actions .edit-button,
    .admin-actions .delete-button {
        width: auto;
    }
}