/* 농정모음 — 붓글씨 먹 로고를 축으로 한 차분한 공공 뉴스 아카이브.
 *
 * 디자인 규칙 (taste: VARIANCE 4 / MOTION 3 / DENSITY 4, redesign-preserve)
 *   - 팔레트: 잉크 근사 검정 + 종이 근사 흰색, 액센트는 농업 녹색 하나뿐.
 *   - 모서리 체계: 면(카드·이미지·대화상자) 10px · 배지 4px · 알약형(칩·버튼) 999px.
 *   - 모션: hover/active 전이와 카드 등장뿐. prefers-reduced-motion 존중.
 */

:root {
  --bg: #f7f8f6;
  --surface: #ffffff;
  --surface-muted: #f0f3ef;
  --text: #1b201b;
  --text-muted: #687169;
  --line: #dce2dc;
  --line-strong: #c9d1ca;
  --accent: #245b38;
  --accent-hover: #19492b;
  --accent-soft: #eaf1ec;
  --badge-press: #245b38;
  --badge-media: #6c5435;
  --badge-media-soft: #f2eee7;
  --radius: 10px;
  --shadow: 0 8px 28px rgb(23 32 25 / 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151916;
    --surface: #1d221e;
    --surface-muted: #222923;
    --text: #edf0ed;
    --text-muted: #a0aaa2;
    --line: #303832;
    --line-strong: #414b43;
    --accent: #8ab99a;
    --accent-hover: #a3caae;
    --accent-soft: #26342a;
    --badge-press: #9ac6a8;
    --badge-media: #d1b17e;
    --badge-media-soft: #352f25;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Pretendard Variable", Pretendard, "Apple SD Gothic Neo", "Noto Sans KR",
    "Malgun Gothic", system-ui, sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  word-break: keep-all;
}

a {
  color: inherit;
  text-decoration: none;
}

.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 28px 80px;
}

/* ── 헤더 ─────────────────────────────────────────── */

.site-header {
  padding: 52px 0 30px;
  border-bottom: 1px solid var(--line-strong);
}

.site-header-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.site-header-compact {
  padding-bottom: 22px;
}

/* 붓글씨 로고 — 흰 배경 PNG 를 multiply 로 종이색 위에 얹는다.
   다크 모드에서는 먹획을 반전해 흰 획으로 만든다. */
.site-logo {
  margin: 0;
  line-height: 0;
}

.site-logo img {
  display: block;
  height: 58px;
  width: auto;
  mix-blend-mode: multiply;
}

.site-logo a {
  display: inline-block;
  transition: opacity 0.18s ease;
}

.site-logo a:hover {
  opacity: 0.72;
}

.site-logo-compact img {
  height: 42px;
}

@media (prefers-color-scheme: dark) {
  .site-logo img {
    filter: invert(1) brightness(1.08);
    mix-blend-mode: screen;
  }
}


/* ── 로그인 ───────────────────────────────────────── */

.auth-controls {
  min-width: 82px;
  display: flex;
  justify-content: flex-end;
}

.auth-login-button,
.auth-logout-button,
.auth-provider,
.icon-button,
.primary-button,
.secondary-button,
.comment-action {
  font: inherit;
  cursor: pointer;
}

.auth-login-button {
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 17px;
  font-size: 0.86rem;
  font-weight: 700;
}

.auth-login-button:hover,
.auth-login-button:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
}

.auth-login-button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.auth-account {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
  font-size: 0.85rem;
}

.auth-avatar,
.comment-avatar {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-muted);
}

.auth-avatar-fallback,
.comment-avatar-fallback {
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 750;
}

.auth-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.auth-separator {
  color: var(--text-muted);
}

.auth-logout-button {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  padding: 5px 0;
  font-size: 0.82rem;
}

.auth-logout-button:hover,
.auth-logout-button:focus-visible {
  color: var(--accent);
}

.auth-dialog {
  width: min(410px, calc(100% - 32px));
  max-width: none;
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--text);
  box-shadow: 0 24px 80px rgb(0 0 0 / 0.25);
}

.auth-dialog::backdrop {
  background: rgb(10 18 12 / 0.55);
  backdrop-filter: blur(2px);
}

.auth-dialog-panel {
  position: relative;
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.auth-dialog-close {
  position: absolute;
  top: 10px;
  right: 12px;
  margin: 0;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.6rem;
  line-height: 1;
}

.auth-dialog-title {
  margin: 0;
  text-align: center;
  font-size: 1.35rem;
}

.auth-dialog-description {
  margin: 8px 0 24px;
  color: var(--text-muted);
  text-align: center;
  font-size: 0.88rem;
}

.auth-providers {
  display: grid;
  gap: 10px;
}

.auth-provider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 700;
}

.auth-provider:hover,
.auth-provider:focus-visible {
  border-color: var(--accent);
}

.auth-provider-kakao {
  border-color: #fee500;
  background: #fee500;
  color: #191919;
}

.auth-provider-mark {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 50%;
  background: rgb(255 255 255 / 0.92);
  color: #333;
  font-size: 0.78rem;
  font-weight: 800;
}

.auth-dialog-status {
  min-height: 1.5em;
  margin: 16px 0 0;
  color: var(--text-muted);
  text-align: center;
  font-size: 0.82rem;
}

/* ── 기관 탭(1차) · 게시판 칩(2차) ────────────────── */

.tabs {
  display: flex;
  gap: 26px;
  margin: 0 0 18px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.board-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 26px;
}

/* display:flex 가 UA 의 [hidden] display:none 을 덮지 않도록 명시한다. */
.board-tabs[hidden] {
  display: none;
}

.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-muted);
  padding: 5px 13px;
  border-radius: 999px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.chip:hover,
.chip:focus-visible {
  border-color: var(--line-strong);
  color: var(--text);
}

.chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.tab {
  position: relative;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  padding: 17px 1px 14px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 650;
  cursor: pointer;
}

.tab:hover,
.tab:focus-visible {
  color: var(--text);
}

.tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.tab.active {
  color: var(--accent);
}

.tab.active::after {
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 2px;
  background: var(--accent);
  content: "";
}

/* ── 피드 카드 ────────────────────────────────────── */

.feed {
  border-top: 0;
}

.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 28px;
  min-height: 190px;
  padding: 24px 0;
  border-bottom: 1px solid var(--line);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

/* 새로 붙는 카드의 도착을 알리는 등장 모션 — 배치 단위로 부드럽게 떠오른다. */
@media (prefers-reduced-motion: no-preference) {
  .card {
    animation: card-in 0.45s cubic-bezier(0.16, 1, 0.3, 1) both;
  }

  @keyframes card-in {
    from {
      opacity: 0;
      transform: translateY(10px);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }
}

.card:hover,
.card:focus-visible {
  border-bottom-color: var(--accent);
  background: linear-gradient(90deg, transparent, var(--surface) 45%, transparent);
}

.card:hover .card-title {
  color: var(--accent);
}

.card:active {
  transform: translateY(1px);
}

.card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

/* API의 원본 width/height 속성보다 목록 레이아웃 크기를 우선하고,
   aspect-ratio로 썸네일 비율을 일정하게 유지한다. */
.card-thumb {
  grid-column: 2;
  grid-row: 1;
  align-self: stretch;
  aspect-ratio: 16 / 10;
  width: 100%;
  height: 100%;
  max-height: 150px;
  object-fit: cover;
  display: block;
  background: var(--surface-muted);
  border-radius: var(--radius);
}

/* 세로형(포스터·인포그래픽)은 가운데 조각만 잘리면 알아볼 수 없으므로
   배경 위에 전체를 담는다. */
.card-thumb.portrait {
  object-fit: contain;
}

.card-body {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  padding: 1px 0;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--badge-press);
}

.badge.media_response {
  background: var(--badge-media-soft);
  color: var(--badge-media);
}

/* 공지·공고, 입법·행정예고, 인물·동정, 공고 — 낮은 채도의 중립 톤. */
.badge.notice,
.badge.legislative_notice,
.badge.people,
.badge.announcement {
  background: var(--surface-muted);
  color: var(--text-muted);
}

/* 기관 배지 — 카테고리 배지보다 톤을 낮춰 보조 정보로 보이게 한다. */
.badge.source {
  background: transparent;
  border: 1px solid var(--line-strong);
  padding: 1px 7px;
  color: var(--text-muted);
  font-weight: 600;
}

.card-title {
  margin: 0;
  font-size: 1.21rem;
  font-weight: 750;
  letter-spacing: -0.028em;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  transition: color 0.15s ease;
}

/* 이미지 없는 게시물은 placeholder 없이 텍스트 중심 카드(§16). 발췌를 한 줄
   더 보여 주어 이미지 자리를 자연스럽게 메운다. */
.card-excerpt {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.87rem;
  line-height: 1.65;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card.text-only {
  grid-template-columns: minmax(0, 1fr);
  min-height: 0;
}

.card.text-only .card-excerpt {
  -webkit-line-clamp: 3;
}

.card-department {
  margin-top: auto;
  padding-top: 2px;
  font-size: 0.76rem;
  color: var(--text-muted);
}

/* ── 무한 스크롤 상태 표시 ────────────────────────── */

.feed-status {
  padding: 36px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.feed-status[hidden] {
  display: none;
}

.spinner {
  display: inline-block;
  width: 22px;
  height: 22px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.retry-button {
  margin-left: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 0.88rem;
  cursor: pointer;
}

.retry-button:active {
  transform: translateY(1px);
}

.retry-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── 상세 페이지 ──────────────────────────────────── */

.article {
  max-width: 760px;
  margin: 0 auto;
}

.back-link {
  display: inline-block;
  margin: 8px 0 20px;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.back-link:hover {
  color: var(--accent);
}

.article-title {
  margin: 10px 0 14px;
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.35;
  word-break: keep-all;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  color: var(--text-muted);
  font-size: 0.88rem;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.article-thumb {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 480px;
  margin: 24px auto 8px;
  border-radius: var(--radius);
}

.article-content {
  margin-top: 22px;
  font-size: 1.04rem;
  line-height: 1.78;
  overflow-wrap: break-word;
}

/* HWP 변환 본문의 문단 리듬. 렌더러가 빈 문단·연속 <br> 을 접은 뒤의
   기본 간격이다 — 과도한 여백은 데이터/렌더 단계에서 이미 제거된다. */
.article-content p {
  margin: 0 0 0.9em;
}

.article-content img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

/* HWP 표는 원본 폭이 본문보다 넓은 경우가 흔하다 — 페이지 대신 표가 가로
   스크롤되게 한다. */
.article-content table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 0.95em;
}

.article-content td,
.article-content th {
  border: 1px solid var(--line);
  padding: 6px 10px;
}

/* 본문 아래에는 원문 보기 버튼 하나만 둔다 — 출처는 상단 배지가 말한다. */
.article-footer {
  margin-top: 36px;
  display: flex;
}

.source-link {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  padding: 9px 20px;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 700;
  transition: background-color 0.15s ease;
}

.source-link:active {
  transform: translateY(1px);
}

.source-link:hover {
  background: var(--accent-hover);
}

/* ── 댓글 ─────────────────────────────────────────── */

.comments-section {
  margin-top: 56px;
  padding-top: 30px;
  border-top: 1px solid var(--line-strong);
}

.comments-heading {
  display: flex;
  align-items: baseline;
  gap: 9px;
  margin-bottom: 8px;
}

.comments-heading h2 {
  margin: 0;
  font-size: 1.2rem;
}

.comments-count {
  color: var(--accent);
  font-size: 0.88rem;
  font-weight: 750;
}

.comments-list {
  border-top: 1px solid var(--line);
}

.comment-item {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 12px;
  padding: 20px 0;
  border-bottom: 1px solid var(--line);
}

.comment-avatar {
  width: 38px;
  height: 38px;
}

.comment-body {
  min-width: 0;
}

.comment-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
}

.comment-author {
  font-size: 0.9rem;
}

.comment-time {
  color: var(--text-muted);
  font-size: 0.76rem;
}

.comment-content {
  margin: 7px 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.94rem;
}

.comment-actions {
  display: flex;
  gap: 10px;
  margin-left: auto;
}

.comment-action {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  padding: 0;
  font-size: 0.76rem;
}

.comment-action:hover,
.comment-action:focus-visible {
  color: var(--accent);
}

.comment-action.danger:hover,
.comment-action.danger:focus-visible {
  color: #b43b35;
}

.comments-status {
  margin: 18px 0;
  color: var(--text-muted);
  font-size: 0.86rem;
  text-align: center;
}

.comments-status[hidden] {
  display: none;
}

.comments-status.error {
  color: #b43b35;
}

.comment-composer {
  margin-top: 24px;
}

.comment-login-prompt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.comment-login-prompt p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.comment-form,
.comment-edit-form {
  display: grid;
  gap: 10px;
}

.comment-textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 13px 14px;
  font: inherit;
  font-size: 0.92rem;
  line-height: 1.55;
}

.comment-textarea:focus {
  border-color: var(--accent);
  outline: 2px solid var(--accent-soft);
}

.comment-form-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.comment-length {
  margin-right: auto;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.primary-button,
.secondary-button {
  border-radius: 7px;
  padding: 8px 16px;
  font-size: 0.86rem;
  font-weight: 700;
}

.primary-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
}

.primary-button:hover,
.primary-button:focus-visible {
  background: var(--accent-hover);
}

.secondary-button {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
}

button:disabled {
  cursor: wait;
  opacity: 0.58;
}

@media (max-width: 640px) {
  .container {
    padding: 0 18px 56px;
  }

  .site-header {
    padding: 28px 0 22px;
  }

  .site-header-main {
    gap: 14px;
  }

  .site-subtitle {
    margin-top: 14px;
    text-align: left;
  }

  .tabs {
    gap: 20px;
    margin-bottom: 28px;
    overflow-x: auto;
  }

  .tab {
    flex: 0 0 auto;
    padding-top: 14px;
  }

  .card {
    grid-template-columns: minmax(0, 1fr) 112px;
    gap: 16px;
    min-height: 142px;
    padding: 20px 0;
  }

  .card-thumb {
    max-height: 90px;
  }

  .card-title {
    font-size: 1.02rem;
  }

  .card-excerpt {
    -webkit-line-clamp: 2;
    font-size: 0.82rem;
  }

  .card-department {
    display: none;
  }

  .article-title {
    font-size: 1.35rem;
  }

  .comment-login-prompt {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 430px) {
  .site-mark {
    width: 38px;
    height: 38px;
  }

  .site-title {
    font-size: 1.45rem;
  }

  .auth-name {
    display: none;
  }

  .auth-separator {
    display: none;
  }

  .card {
    display: flex;
    flex-direction: column;
    gap: 14px;
  }

  .card-thumb {
    aspect-ratio: 16 / 9;
    max-height: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── 농정모음 리디자인: 좁은 화면 보정 ────────────── */

@media (max-width: 640px) {
  .site-header {
    padding-top: 34px;
  }

  .site-logo img {
    height: 46px;
  }
}

/* 익명 댓글 아바타 — 코드 첫 글자를 담백한 원 안에. */
.comment-avatar-anon {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.82rem;
}

/* ── 내 댓글 페이지 (/my-comments) ────────────────── */

.my-comments-page {
  max-width: 760px;
  margin: 0 auto;
}

.page-title {
  margin: 10px 0 18px;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.my-comments-list {
  border-top: 1px solid var(--line-strong);
}

.load-more-wrap {
  display: flex;
  justify-content: center;
  margin-top: 22px;
}

.load-more {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  padding: 9px 26px;
  border-radius: 999px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

.load-more:hover,
.load-more:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
}

.load-more[hidden] {
  display: none;
}

.load-more:active {
  transform: translateY(1px);
}

.my-comment-item {
  padding: 13px 2px;
  border-top: 1px solid var(--line);
}

.my-comment-item:first-child {
  border-top: 0;
}

.my-comment-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
}

.my-comment-article {
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.88rem;
  font-weight: 700;
}

.my-comment-article:hover {
  color: var(--accent);
}

.my-comment-content {
  margin: 6px 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* 아바타+이름 = "내 댓글" 여는 버튼. */
.auth-me {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 3px 4px;
  border-radius: 999px;
  font: inherit;
  cursor: pointer;
}

.auth-me:hover .auth-name,
.auth-me:focus-visible .auth-name {
  color: var(--accent);
}

/* ── 첨부파일 링크 (본문 아래, 기관 원본으로 연결) ── */

.article-attachments {
  margin-top: 34px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.article-attachments-title {
  margin: 0 0 10px;
  font-size: 0.95rem;
  font-weight: 750;
}

.article-attachments-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 7px;
}

.article-attachment {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  color: var(--accent);
  font-size: 0.92rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  overflow-wrap: anywhere;
}

.article-attachment:hover {
  color: var(--accent-hover);
}

.article-attachment-size {
  color: var(--text-muted);
  font-size: 0.78rem;
  text-decoration: none;
}
