:root {
  --color-bg: #faf6f4;
  --color-surface: #ffffff;
  --color-primary: #b8758c;
  --color-primary-dark: #9c5f74;
  --color-primary-soft: #f6e8ec;
  --color-text: #332e2c;
  --color-text-muted: #948c87;
  --color-border: #ece3e0;
  --color-danger: #d8696f;
  --color-danger-soft: #fbeaea;
  --color-success: #6f9c84;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(51, 46, 44, 0.05);
  --shadow-md: 0 8px 24px rgba(51, 46, 44, 0.08);
}

* { box-sizing: border-box; }

body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--color-primary-dark); }

/* ── 네비게이션 바 ────────────────────────────────────── */

.app-navbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-navbar .brand {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-text);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.app-navbar .brand::before {
  content: '♥';
  color: var(--color-primary);
  margin-right: 6px;
}

.app-navbar .nav-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-select {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.85rem;
  background: var(--color-surface);
  color: var(--color-text);
}

.btn-logout {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 0.85rem;
  background: var(--color-surface);
  color: var(--color-text-muted);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.btn-logout:hover { background: var(--color-bg); color: var(--color-text); }

/* ── 공통 버튼 ────────────────────────────────────────── */

.btn-app-primary {
  background: var(--color-primary);
  border: none;
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 8px 18px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn-app-primary:hover { background: var(--color-primary-dark); }
.btn-app-primary:active { transform: scale(0.98); }
.btn-app-primary:disabled { opacity: 0.5; cursor: default; }

.btn-app-outline {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-app-outline:hover { background: var(--color-bg); border-color: var(--color-primary); }

.btn-app-accent {
  background: var(--color-primary-soft);
  border: 1px solid var(--color-primary);
  color: var(--color-primary-dark);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-app-accent:hover { background: var(--color-primary); color: #fff; }

.btn-app-danger {
  background: var(--color-danger-soft);
  border: 1px solid var(--color-danger);
  color: #9c3d42;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-app-danger:hover { background: var(--color-danger); color: #fff; }

/* ── 레이아웃 ─────────────────────────────────────────── */

.app-shell { padding: 32px 28px; max-width: 1280px; margin: 0 auto; }

.layout-grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 28px;
  align-items: start;
}
@media (max-width: 860px) {
  .layout-grid { grid-template-columns: 1fr; }
}
.panel-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 14px;
}

/* 좌/우 패널 헤더 높이를 통일해서 그 아래 카드 윗단이 항상 같은 줄에 맞도록 한다
   (버튼이 있는 헤더와 텍스트만 있는 헤더의 높이가 달라서 어긋나 보이던 문제) */
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 38px;
  margin-bottom: 14px;
  gap: 8px;
}
.panel-header .panel-title { margin-bottom: 0; }
.panel-empty {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.85rem;
  padding: 64px 16px;
}

.app-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

/* ── 카테고리 트리 ────────────────────────────────────── */

.cat-row-inner {
  display: flex;
  align-items: center;
  padding: 11px 16px;
  border-bottom: 1px solid var(--color-border);
  gap: 8px;
  min-height: 46px;
  cursor: pointer;
  transition: background 0.12s;
}
.cat-row:last-child > .cat-row-inner { border-bottom: none; }
.cat-row-inner:hover { background: var(--color-bg); }
.cat-row-selected > .cat-row-inner {
  background: var(--color-primary-soft);
  box-shadow: inset 3px 0 0 var(--color-primary);
}

.cat-bullet {
  flex-shrink: 0;
  width: 16px;
  text-align: center;
  font-size: 0.6rem;
  color: var(--color-text-muted);
}
.cat-depth-0 > .cat-row-inner .cat-bullet { color: var(--color-primary); font-size: 0.55rem; }

.cat-name-text {
  flex: 1;
  font-size: 0.88rem;
  color: var(--color-text);
  word-break: break-all;
}
.cat-depth-0 > .cat-row-inner .cat-name-text { font-weight: 700; }

.cat-actions {
  display: flex;
  gap: 2px;
  align-items: center;
  opacity: 0;
  transition: opacity 0.12s;
  flex-shrink: 0;
}
.cat-row-inner:hover .cat-actions { opacity: 1; }

.act-divider { width: 1px; height: 14px; background: var(--color-border); margin: 0 3px; flex-shrink: 0; }

.btn-act {
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  font-size: 0.74rem;
  cursor: pointer;
  color: var(--color-text-muted);
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn-act:hover { background: var(--color-bg); border-color: var(--color-border); color: var(--color-text); }
.btn-act:disabled { opacity: 0.3; cursor: default; pointer-events: none; }
.btn-act.add:hover { background: var(--color-primary-soft); border-color: var(--color-primary); color: var(--color-primary-dark); }
.btn-act.del:hover { background: var(--color-danger-soft); border-color: var(--color-danger); color: var(--color-danger); }

.btn-toggle {
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  width: 20px;
  height: 20px;
  padding: 0;
  cursor: pointer;
  font-size: 0.55rem;
  color: var(--color-text-muted);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.btn-toggle:hover { background: var(--color-primary-soft); color: var(--color-primary-dark); }
.toggle-spacer { width: 20px; flex-shrink: 0; display: inline-block; }

.cat-inline-input {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-primary-soft);
}
.cat-inline-input input {
  flex: 1;
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-size: 0.85rem;
  outline: none;
  min-width: 0;
  background: var(--color-surface);
}

/* ── 카테고리 필드 패널 ───────────────────────────────── */

.field-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--color-border);
}
.field-row:last-child { border-bottom: none; }
.field-row.field-row-create { background: var(--color-primary-soft); }
.field-row.dragging { opacity: 0.4; }
.field-name-input { max-width: 220px; }
.field-type-select { max-width: 140px; }

.field-drag-handle {
  cursor: grab;
  color: var(--color-text-muted);
  font-size: 1rem;
  line-height: 1;
  padding: 4px 2px;
  user-select: none;
}
.field-drag-handle:active { cursor: grabbing; }

.field-row-actions { display: flex; gap: 4px; }

/* ── 입력 폼 공통 ─────────────────────────────────────── */

.app-input, .app-select-input {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 9px 13px;
  font-size: 0.88rem;
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.app-input:focus, .app-select-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}
.app-input[readonly] { background: var(--color-bg); color: var(--color-text-muted); }

.field-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}

.field-block { margin-bottom: 18px; }

/* ── 항목 목록 ────────────────────────────────────────── */

.entry-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  transition: background 0.12s;
}
.entry-row:last-child { border-bottom: none; }
.entry-row:hover { background: var(--color-bg); }

.entry-row-main { min-width: 0; flex: 1; }
.entry-row-label {
  display: block;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.entry-row-label.is-struck {
  text-decoration: line-through;
  color: var(--color-text-muted);
  font-weight: 500;
}
.entry-row-preview {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.entry-row-side {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.entry-row-date { font-size: 0.76rem; color: var(--color-text-muted); }

.confirm-badge {
  font-size: 0.72rem;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  white-space: nowrap;
}
.confirm-badge:hover { border-color: var(--color-primary); color: var(--color-primary-dark); }
.confirm-badge.is-confirmed {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}
.confirm-badge.is-confirmed:hover { background: var(--color-primary-dark); }

/* ── 알림 토스트 ──────────────────────────────────────── */

.app-toast {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  min-width: 260px;
  max-width: 360px;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: toast-in 0.18s ease-out;
}
.app-toast.success { background: #eef6f1; color: #3f6c54; border: 1px solid #cfe6da; }
.app-toast.danger { background: var(--color-danger-soft); color: #9c3d42; border: 1px solid #f2cdcf; }
.app-toast-close {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  opacity: 0.6;
  font-size: 0.95rem;
  line-height: 1;
}
.app-toast-close:hover { opacity: 1; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── 사진 첨부 ────────────────────────────────────────── */

.image-thumb-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}
.image-thumb {
  position: relative;
  width: 96px;
  height: 96px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
}
.image-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
  display: block;
}
.image-thumb-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.image-thumb-remove:hover { background: rgba(0, 0, 0, 0.75); }

/* ── 로그인 화면 ──────────────────────────────────────── */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 40px 32px;
}
.login-title {
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 28px;
  color: var(--color-text);
}
.login-title::before {
  content: '♥';
  display: block;
  color: var(--color-primary);
  font-size: 1.5rem;
  margin-bottom: 8px;
}
/* ── 필수 입력 표시 ───────────────────────────────────── */

.required-star { color: var(--color-danger); font-weight: 700; }
.field-row-locked {
  background: var(--color-primary-soft);
  border-left: 3px solid var(--color-primary);
}
.field-locked-name {
  font-weight: 600;
  color: var(--color-text);
  background: #f5eaed;
  cursor: default;
  pointer-events: none;
}
.field-locked-desc {
  flex: 1;
  font-size: 0.78rem;
  color: var(--color-text-muted);
}
.field-locked-badge {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--color-primary-dark);
  background: #f0d4dc;
  border-radius: 4px;
  padding: 3px 8px;
  white-space: nowrap;
}
.field-required-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  cursor: pointer;
}

/* ── 라이트박스 ───────────────────────────────────────── */

.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.lightbox-img {
  max-width: 92vw;
  max-height: 88vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
  cursor: default;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}
.lightbox-close {
  position: fixed;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.8;
}
.lightbox-close:hover { opacity: 1; }

.login-alert {
  background: var(--color-danger-soft);
  color: #9c3d42;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.82rem;
  margin-bottom: 16px;
}

/* ── 정리본 직접 수정 ─────────────────────────────────── */

.summary-edit-area { display: flex; flex-direction: column; }
.summary-wysiwyg { border: 1px solid #d0d0d0; border-radius: 8px; overflow: hidden; }
.summary-wysiwyg .toastui-editor-toolbar { background: #fafafa; border-bottom: 1px solid #e0e0e0; }
.summary-wysiwyg .toastui-editor-contents { font-family: 'Pretendard', sans-serif; font-size: 0.88rem; line-height: 1.75; }
.summary-wysiwyg .toastui-editor-ww-container { background: #fff; }
.summary-wysiwyg .ProseMirror { min-height: 160px; padding: 12px 16px; }

/* ── 이전 버전 패널 ───────────────────────────────────── */

.prev-version-area { margin-top: 16px; padding: 14px 16px; background: #fdf6ee; border: 1px solid #e8d8c0; border-radius: 8px; }
.prev-version-label { font-size: 0.75rem; font-weight: 600; color: #a07840; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 10px; }
.prev-version-content { font-size: 0.87rem; line-height: 1.75; color: #555; }

/* ── AI 요약 마크다운 렌더링 ──────────────────────────── */

.ai-summary {
  font-size: 0.9rem;
  line-height: 1.75;
  color: var(--color-text);
}
.ai-summary p {
  margin: 0 0 0.6em;
}
.ai-summary ul, .ai-summary ol {
  margin: 0.2em 0 0.7em;
  padding-left: 1.5em;
}
.ai-summary li {
  margin-bottom: 0.3em;
}
.ai-summary strong {
  font-weight: 600;
  color: var(--color-text);
}
.ai-summary p:last-child, .ai-summary li:last-child {
  margin-bottom: 0;
}
/* 카드 타이틀 (첫 번째 굵은 줄) */
.ai-summary > p:first-child strong,
.ai-summary p:first-of-type strong {
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}
/* 구분선 */
.ai-summary hr {
  border: none;
  border-top: 1px solid #e8e0d8;
  margin: 14px 0;
}
/* 섹션 헤더 (📌 💰 🔍) */
.ai-summary p strong:only-child {
  display: block;
  margin-top: 4px;
  margin-bottom: 6px;
  font-size: 0.88rem;
  color: #5a4a3c;
}
/* 테이블 */
.ai-summary table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 1em;
  font-size: 0.855rem;
}
.ai-summary th, .ai-summary td {
  padding: 7px 12px;
  text-align: left;
  border: 1px solid #e8e0d8;
}
.ai-summary th {
  background: #f5efe9;
  font-weight: 600;
  color: #5a4a3c;
  white-space: nowrap;
}
.ai-summary tr:nth-child(even) td {
  background: #faf7f4;
}
.ai-summary td:first-child {
  font-weight: 500;
  color: #6b5c4e;
  white-space: nowrap;
  width: 1%;
}
/* 참고 자료 링크 */
.ai-summary a {
  color: #9b7b5c;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}

/* ── 상세 뷰 액션 버튼 행 ────────────────────────────────── */

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

/* ── 모바일 반응형 ────────────────────────────────────────── */

@media (max-width: 600px) {
  /* 전체 여백 축소 */
  .app-shell { padding: 12px; }
  .app-navbar { padding: 10px 14px; }

  /* 그리드: 모바일에서 패널 간격 줄이기 */
  .layout-grid { gap: 16px; }

  /* 패널 헤더: 타이틀 위, 버튼 아래로 */
  .panel-header {
    flex-direction: column;
    align-items: flex-start;
    min-height: auto;
    gap: 10px;
    margin-bottom: 10px;
  }

  /* 버튼 크기 축소 */
  .btn-app-primary, .btn-app-outline, .btn-app-accent, .btn-app-danger {
    padding: 7px 11px;
    font-size: 0.8rem;
  }
  .confirm-badge { padding: 5px 10px; font-size: 0.78rem; }

  /* 상세 뷰 액션 행 */
  .detail-actions { gap: 6px; }

  /* 카드 내부 패딩 축소 */
  .app-card > div[style*="padding: 22px"] { padding: 14px !important; }

  /* AI 요약 테이블: 가로 스크롤 */
  .ai-summary { overflow-x: auto; }
  .ai-summary table { min-width: 260px; font-size: 0.8rem; }
  .ai-summary th, .ai-summary td { padding: 6px 9px; }

  /* 폼 저장 버튼 행 */
  .field-block + div[style*="display:flex"],
  .summary-edit-area > .btn-app-primary { width: 100%; }

  /* 토스트 알림 */
  .app-toast {
    left: 10px;
    right: 10px;
    top: 10px;
    min-width: 0;
    max-width: none;
  }

  /* 이미지 썸네일 */
  .image-thumb { width: 80px; height: 80px; }

  /* 카테고리 관리 — 필드 목록: 한 줄에 다 안 들어가니 여러 줄로 감싼다 */
  .field-row {
    flex-wrap: wrap;
    row-gap: 8px;
    padding: 10px 12px;
  }
  .field-row-locked { align-items: flex-start; }
  .field-locked-name {
    flex: 1 1 100%;
    font-size: 0.82rem;
    padding: 8px 10px;
  }
  .field-locked-desc { flex: 1 1 auto; font-size: 0.7rem; }
  .field-locked-badge { flex: 0 0 auto; }
  .field-name-input { flex: 1 1 120px; max-width: none; min-width: 0; }
  .field-type-select { flex: 1 1 90px; max-width: none; min-width: 0; }
  .field-required-label { flex: 0 0 auto; }
  .field-row-actions { flex: 1 1 100%; justify-content: flex-end; }
}
