/* ============================================
   notes.css — 메모 탭 전용 (쇼핑 .shop-* 와 완전 분리)
   모든 선택자는 #panel-notes 로 스코프 제한
   ============================================ */

/* 메모 탭: 앱 공통 헤더 대신 내부 「메모」 타이틀 사용 */
.app-shell[data-active-tab="notes"] .app-header {
  display: none;
}

/*
 * 메모 탭은 자식(.notes-screen)이 전부 absolute 라 흐름 높이가 0이 됨.
 * 쇼핑 탭(#panel-shopping)처럼 flex 열로 남는 영역을 채운 뒤,
 * .notes-app 안에서 absolute 자식이 inset:0 으로 맞춤.
 */
#panel-notes {
  padding: 0;
  overflow: hidden;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  background: var(--color-bg);
}

/* display 는 layout.css 의 .tab-panel.is-active 만 사용 (hidden 과 충돌 방지) */
#panel-notes.tab-panel.is-active {
  position: relative;
  flex-direction: column;
  /*
   * 구 layout(.app-main display:block)에서도 높이 확보.
   * 메모 탭은 공통 헤더를 숨기므로 탭바·safe-area만 제외.
   */
  min-height: calc(100dvh - var(--tab-bar-height) - var(--safe-bottom));
}

#panel-notes .notes-app {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  width: auto;
  height: auto;
  min-height: 0;
  overflow: hidden;
  background: var(--color-bg);
}

/* ---------- 공통: 두 화면 슬라이드 레이어 ---------- */
#panel-notes .notes-screen,
#panel-notes #notesListScreen,
#panel-notes #notesEditScreen {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  transition: transform var(--transition-slow) cubic-bezier(0.32, 0.72, 0, 1);
  will-change: transform;
}

#panel-notes .notes-screen--list {
  z-index: 1;
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
}

#panel-notes .notes-screen--edit {
  z-index: 2;
  transform: translateX(100%);
  visibility: hidden;
  pointer-events: none;
}

/* 편집 모드: 리스트는 왼쪽으로, 편집 화면이 들어옴 */
#panel-notes .notes-app[data-notes-view="edit"] .notes-screen--list {
  transform: translateX(-100%);
  visibility: hidden;
  pointer-events: none;
}

#panel-notes .notes-app[data-notes-view="edit"] .notes-screen--edit {
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
}

/* ---------- [1] 리스트 화면 ---------- */
#panel-notes .notes-list-head {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  padding-top: calc(var(--safe-top) + var(--tab-title-pad-before));
  padding-bottom: 0;
  padding-left: var(--tab-title-pad-inline);
  padding-right: var(--tab-title-pad-inline);
  background: var(--color-bg);
  border-bottom: none;
  color: var(--color-text);
}

#panel-notes .notes-list-head__title {
  margin: 0;
  padding-top: var(--tab-title-pad-after);
  font-size: var(--text-greeting);
  font-weight: var(--font-bold);
  line-height: var(--line-height-relaxed);
  color: var(--color-text);
  word-break: keep-all;
}

#panel-notes .notes-list-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* FAB + 하단 탭바 여백 */
  padding-bottom: calc(80px + var(--tab-bar-height) + var(--safe-bottom));
}

#panel-notes .notes-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

/* 메모 리스트만: 컨테이너 무라운드 → 삭제 영역도 직각 */
#panel-notes .swipe-wrapper {
  border-radius: 0;
}

#panel-notes .swipe-action {
  border-radius: 0;
}

#panel-notes .swipe-content > .notes-row {
  text-align: left;
  padding: var(--space-4);
  min-height: 72px;
  background: var(--color-bg-elevated);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-sm);
  border-top-right-radius: calc(var(--radius-sm) * (1 - var(--swipe-reveal, 0)));
  border-bottom-right-radius: calc(var(--radius-sm) * (1 - var(--swipe-reveal, 0)));
  cursor: pointer;
}

#panel-notes .swipe-wrapper:not(.is-dragging) .swipe-content > .notes-row {
  transition:
    border-top-right-radius var(--transition-base),
    border-bottom-right-radius var(--transition-base);
}

#panel-notes .notes-row:active {
  background: var(--color-accent-bg);
}

#panel-notes .notes-row__title {
  font-size: var(--text-base);
  font-weight: var(--font-bold);
  color: var(--color-text);
  margin: 0 0 var(--space-1);
  word-break: break-word;
}

#panel-notes .notes-row__preview {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: 0 0 var(--space-1);
  line-height: var(--line-height-relaxed);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

#panel-notes .notes-row__preview--empty {
  color: var(--color-text-muted);
  font-style: italic;
}

#panel-notes .notes-row__date {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin: 0;
}

#panel-notes .notes-empty {
  text-align: center;
  padding: var(--space-8);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* ---------- [2] 편집 화면 ---------- */
#panel-notes .notes-edit-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: calc(var(--safe-top) + var(--space-1)) var(--space-4) var(--space-2);
  background: var(--color-bg-elevated);
  border-bottom: var(--border-width) solid var(--color-border);
}

#panel-notes .notes-edit-head__back,
#panel-notes .notes-edit-head__done {
  font-size: var(--text-base);
  font-weight: var(--font-medium);
  color: var(--color-accent);
  min-height: var(--touch-target-min);
  padding: 0;
  background: transparent;
  border: none;
}

#panel-notes .notes-edit-head__done {
  font-weight: var(--font-semibold);
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
}

/* 완료 버튼이 터치되도록 상단 바를 다른 레이어 위에 */
#panel-notes .notes-edit-head {
  position: relative;
  z-index: 4;
  pointer-events: auto;
}

/* iOS 키보드 내리기용 (notes.js 가 body 에 추가) */
.notes-keyboard-dismiss {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

#panel-notes .notes-screen--edit {
  display: flex;
  flex-direction: column;
}

#panel-notes .notes-format-bar {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4) var(--space-4);
  background: var(--color-bg-elevated);
  border-bottom: var(--border-width) solid var(--color-border);
}

#panel-notes .notes-format-bar__row {
  display: flex;
  align-items: stretch;
  gap: var(--space-2);
  min-width: 0;
}

#panel-notes .notes-format-bar__row--styles {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}

#panel-notes .notes-format-bar__row--styles::-webkit-scrollbar {
  display: none;
}

#panel-notes .notes-format-bar__row--tools {
  justify-content: space-between;
  gap: var(--space-3);
}

#panel-notes .notes-format-bar__group {
  display: flex;
  align-items: stretch;
  gap: var(--space-2);
  padding: var(--space-1);
  border-radius: var(--radius-md);
  background: var(--color-bg-subtle);
}

#panel-notes .notes-format-bar__btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-target-min);
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-bg);
  border: var(--border-width) solid var(--color-border);
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast),
    color var(--transition-fast),
    box-shadow var(--transition-fast);
}

#panel-notes .notes-format-bar__btn--style {
  min-width: 4.5rem;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  white-space: nowrap;
}

#panel-notes .notes-format-bar__btn--title {
  font-size: 1.25rem;
  font-weight: var(--font-bold);
  line-height: 1.2;
}

#panel-notes .notes-format-bar__btn--heading {
  font-size: var(--text-lg);
  font-weight: var(--font-bold);
  line-height: 1.2;
}

#panel-notes .notes-format-bar__btn--body {
  font-size: var(--text-base);
  font-weight: var(--font-medium);
  line-height: 1.2;
}

#panel-notes .notes-format-bar__btn--mono {
  font-size: calc(var(--text-base) - 3px);
  font-weight: var(--font-medium);
  font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", monospace;
  line-height: 1.2;
}

#panel-notes .notes-format-bar__btn--inline {
  min-width: var(--touch-target-min);
  font-size: var(--text-lg);
  font-weight: var(--font-bold);
}

#panel-notes .notes-format-bar__btn--inline i,
#panel-notes .notes-format-bar__btn--inline u {
  font-style: inherit;
  text-decoration: inherit;
}

#panel-notes .notes-format-bar__btn--list {
  min-width: var(--touch-target-min);
  font-size: var(--text-xl);
  font-weight: var(--font-medium);
}

#panel-notes .notes-format-bar__btn.is-active {
  background: var(--color-accent-bg);
  border-color: var(--color-accent);
  color: var(--color-accent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--color-accent) 35%, transparent);
}

#panel-notes .notes-format-bar__btn--style.is-active {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-header-fg);
  box-shadow: none;
}

#panel-notes .notes-editor {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-4);
  padding-bottom: calc(var(--tab-bar-height) + var(--safe-bottom) + var(--space-6));
  font-size: var(--text-base);
  line-height: var(--line-height-relaxed);
  outline: none;
  min-height: 120px;
  word-break: break-word;
  background: var(--color-bg);
}

#panel-notes .notes-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--color-text-muted);
  white-space: pre-line;
}

#panel-notes .notes-editor p {
  font-weight: var(--font-medium);
  margin: var(--space-2) 0;
}

#panel-notes .notes-editor h1 {
  font-size: 1.5rem;
  font-weight: var(--font-bold);
  margin: var(--space-2) 0;
}

#panel-notes .notes-editor h2 {
  font-size: var(--text-lg);
  font-weight: var(--font-bold);
  margin: var(--space-2) 0;
}

#panel-notes .notes-editor p.notes-mono {
  font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", monospace;
  font-size: calc(var(--text-base) - 3px);
  font-weight: var(--font-medium);
  margin: var(--space-2) 0;
}

#panel-notes .notes-editor ul:not(.notes-checklist),
#panel-notes .notes-editor ol {
  margin: var(--space-2) 0;
  padding-left: var(--space-6);
}

#panel-notes .notes-editor ul:not(.notes-checklist) {
  list-style: disc;
}

#panel-notes .notes-editor ol {
  list-style: decimal;
}

/* 체크리스트: 글머리(•) 없이 ☐/☑ 만 (::before) */
#panel-notes .notes-editor ul.notes-checklist {
  list-style: none !important;
  list-style-type: none !important;
  padding-left: 0 !important;
  margin: var(--space-2) 0;
}

#panel-notes .notes-editor ul.notes-checklist > li {
  position: relative;
  list-style: none !important;
  list-style-type: none !important;
  padding-left: 2.25em;
  min-height: 1.75em;
  margin: var(--space-2) 0;
}

#panel-notes .notes-editor ul.notes-checklist > li::before {
  content: "☐";
  position: absolute;
  left: 0;
  top: 0.05em;
  line-height: 1.2;
  font-size: 1.45em;
}

#panel-notes .notes-editor ul.notes-checklist > li.is-checked::before {
  content: "☑";
}
