:root {
  --green: #00a82d;
  --green-dark: #008a25;
  --sidebar-bg: #1d2b36;
  --sidebar-text: #c9d4de;
  --sidebar-muted: #8496a5;
  --panel: #ffffff;
  --list-bg: #f7f7f5;
  --hover: #efefec;
  --border: #e4e4e0;
  --text: #2b2b28;
  --muted: #73736e; /* 4.5:1 대비 (AA) */
  --code-bg: #f4f5f3;
  --quote-bg: #f8faf8;
  --chip-bg: #e6f4ea;
  --chip-text: #21753a;
  --danger: #d64541;
  --danger-bg: #fde8e7;
  --toast-bg: #2b2b28;
  --toast-text: #ffffff;
  --login-bg: linear-gradient(160deg, #f2f7f3, #dff0e3);
  color-scheme: light;
}

/* 수동 다크모드 */
:root[data-theme='dark'] {
  --green-dark: #00c235;
  --sidebar-bg: #131c25;
  --sidebar-text: #c2cdd8;
  --sidebar-muted: #74838f;
  --panel: #21211f;
  --list-bg: #191918;
  --hover: #2b2b29;
  --border: #383835;
  --text: #e6e6e1;
  --muted: #97978f;
  --code-bg: #2c2c2a;
  --quote-bg: #242824;
  --chip-bg: #1f3d2a;
  --chip-text: #8fdca3;
  --danger: #e0604f;
  --danger-bg: #3a2422;
  --toast-bg: #e8e8e4;
  --toast-text: #1c1c1a;
  --login-bg: linear-gradient(160deg, #16211a, #101a13);
  color-scheme: dark;
}

/* 시스템 다크모드 (수동으로 라이트를 고르지 않았을 때) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --green-dark: #00c235;
    --sidebar-bg: #131c25;
    --sidebar-text: #c2cdd8;
    --sidebar-muted: #74838f;
    --panel: #21211f;
    --list-bg: #191918;
    --hover: #2b2b29;
    --border: #383835;
    --text: #e6e6e1;
    --muted: #97978f;
    --code-bg: #2c2c2a;
    --quote-bg: #242824;
    --chip-bg: #1f3d2a;
    --chip-text: #8fdca3;
    --danger: #e0604f;
    --danger-bg: #3a2422;
    --toast-bg: #e8e8e4;
    --toast-text: #1c1c1a;
    --login-bg: linear-gradient(160deg, #16211a, #101a13);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Malgun Gothic', 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
  color: var(--text);
  background: var(--panel);
  overscroll-behavior: none;
}

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; color: var(--text); }

/* SVG 아이콘: currentColor 상속 스트로크 */
.icon {
  width: 1.1em;
  height: 1.1em;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.18em;
  flex-shrink: 0;
}
.icon.filled { fill: currentColor; }
.icon.gold { color: #f5b921; }

/* 키보드 포커스 가시화 (접근성) */
button:focus-visible, select:focus-visible, .nav-item:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 1px;
}

.icon-btn {
  border: none;
  background: transparent;
  font-size: 15px;
  padding: 4px 7px;
  border-radius: 6px;
  color: inherit;
  line-height: 1;
}
.icon-btn:hover { background: rgba(128, 128, 128, 0.18); }
.icon-btn.danger:hover { background: var(--danger-bg); color: var(--danger); }
.icon-btn.small { font-size: 13px; padding: 2px 6px; }
.icon-btn.star { font-size: 17px; color: var(--muted); }
.icon-btn.star.active { color: #f5b921; }

/* ---------- 로그인 ---------- */
.login {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--login-bg);
}
.login-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  background: var(--panel);
  padding: 40px 44px;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 30, 10, 0.25);
  width: min(320px, 86vw);
}
.login-card h1 { margin: 0 0 6px; font-size: 22px; }
.login-card input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  background: var(--list-bg);
}
.login-card input:focus { outline: 2px solid var(--green); border-color: transparent; }
.login-card button {
  width: 100%;
  padding: 11px;
  border: none;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}
.login-card button:hover { background: var(--green-dark); }
.login-error { color: var(--danger); font-size: 13px; min-height: 1em; margin: 0; }

/* ---------- 앱 레이아웃 ---------- */
.app {
  display: grid;
  grid-template-columns: 235px 320px 1fr;
  grid-template-rows: minmax(0, 1fr); /* 패널이 뷰포트를 넘지 않게 (내부 스크롤 보장) */
  height: 100dvh;
}

/* ---------- 사이드바 ---------- */
.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.sidebar-head {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 14px 10px;
}
.logo { font-weight: 700; font-size: 16px; flex: 1; color: #fff; display: flex; align-items: center; gap: 7px; }
.logo .icon { color: #57d06d; }
.sync-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #57d06d;
  flex-shrink: 0;
  margin-right: 4px;
}
.sync-dot.syncing { background: #f5c542; animation: pulse 1s infinite; }
.sync-dot.offline { background: #9aa7b1; }
.sync-dot.error { background: #e0604f; }
@keyframes pulse { 50% { opacity: 0.35; } }

.sidebar-search { padding: 0 12px 10px; }
.sidebar-search input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 7px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 13.5px;
}
.sidebar-search input::placeholder { color: var(--sidebar-muted); }
.sidebar-search input:focus { outline: 2px solid var(--green); }

.sidebar-nav { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 8px; }
.nav-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 8px 4px;
  font-size: 11.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--sidebar-muted);
}
.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 7px 8px;
  border-radius: 7px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}
.nav-item > span:first-child { overflow: hidden; text-overflow: ellipsis; }
.nav-item:hover { background: rgba(255, 255, 255, 0.07); }
.nav-item.active { background: var(--green); color: #fff; }
.nav-item .count { font-size: 12px; color: var(--sidebar-muted); }
.nav-item.active .count { color: #d8f5de; }
.nav-item-end { display: flex; align-items: center; gap: 2px; }
.nav-item .menu { opacity: 0; }
.nav-item:hover .menu { opacity: 1; }

.sidebar-foot {
  padding: 10px 14px;
  font-size: 12px;
  color: var(--sidebar-muted);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* ---------- 노트 목록 ---------- */
.notelist {
  background: var(--list-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.notelist-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.notelist-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; }
.notelist-title strong { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); font-size: 12.5px; }
.new-note-btn {
  border: none;
  background: var(--green);
  color: #fff;
  border-radius: 7px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.new-note-btn:hover { background: var(--green-dark); }
.hamburger { display: none; }

.notelist-items { flex: 1; min-height: 0; overflow-y: auto; }
.note-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  background: transparent;
}
.note-item:hover { background: var(--hover); }
.note-item.selected { background: var(--panel); box-shadow: inset 3px 0 0 var(--green); }
.note-item-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.note-item-title {
  font-weight: 600;
  font-size: 14.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.note-item-date { font-size: 11.5px; color: var(--muted); flex-shrink: 0; }
.note-item-snippet {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.note-item-tags { margin-top: 5px; display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--chip-bg);
  color: var(--chip-text);
  font-size: 11px;
  border-radius: 20px;
  padding: 2px 8px;
}
.notelist-empty { text-align: center; color: var(--muted); padding: 48px 20px; font-size: 14px; line-height: 1.7; }

/* ---------- 에디터 ---------- */
.editor { display: flex; flex-direction: column; min-width: 0; background: var(--panel); }
.editor-inner { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.editor-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.editor-head .back { display: none; }
#note-title {
  flex: 1;
  min-width: 60px;
  border: none;
  font-size: 19px;
  font-weight: 700;
  padding: 4px 2px;
  background: transparent;
}
#note-title:focus { outline: none; }
#note-notebook {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 6px;
  font-size: 12.5px;
  background: var(--panel);
  max-width: 150px;
}
.mode-toggle { display: flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.mode-toggle button {
  border: none;
  background: var(--panel);
  color: var(--text);
  padding: 5px 10px;
  font-size: 13px;
}
.mode-toggle button.active { background: var(--green); color: #fff; }

.tags-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
}
.chip.editable button {
  border: none;
  background: none;
  color: inherit;
  font-size: 12px;
  padding: 0 0 0 2px;
  opacity: 0.6;
}
.chip.editable button:hover { opacity: 1; }
#tag-input {
  border: none;
  font-size: 12.5px;
  padding: 4px;
  min-width: 110px;
  flex: 1;
  background: transparent;
}
#tag-input:focus { outline: none; }

.editor-body {
  flex: 1;
  display: grid;
  min-height: 0;
  grid-template-columns: 1fr 1fr;
}
.editor-body.mode-edit { grid-template-columns: 1fr; }
.editor-body.mode-edit #preview { display: none; }
.editor-body.mode-preview { grid-template-columns: 1fr; }
.editor-body.mode-preview #note-body { display: none; }

#note-body {
  border: none;
  resize: none;
  padding: 18px 20px;
  font-size: 14.5px;
  line-height: 1.7;
  font-family: 'Consolas', 'D2Coding', monospace, 'Malgun Gothic';
  min-height: 0;
  background: transparent;
}
#note-body:focus { outline: none; }
.editor-body.mode-split #note-body { border-right: 1px solid var(--border); }

.preview { overflow-y: auto; padding: 18px 22px; min-height: 0; }

.editor-foot {
  padding: 7px 14px;
  font-size: 11.5px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}
.editor-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.8;
  height: 100%;
}

/* ---------- 마크다운 미리보기 ---------- */
.markdown-body { font-size: 14.5px; line-height: 1.75; word-break: break-word; }
.markdown-body h1, .markdown-body h2 { border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.markdown-body h1 { font-size: 1.7em; }
.markdown-body h2 { font-size: 1.4em; }
.markdown-body pre {
  background: var(--code-bg);
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 13px;
}
.markdown-body code { background: var(--code-bg); border-radius: 4px; padding: 1px 5px; font-size: 0.9em; }
.markdown-body pre code { background: none; padding: 0; }
.markdown-body blockquote {
  margin: 0.6em 0;
  padding: 2px 14px;
  border-left: 4px solid var(--green);
  color: var(--muted);
  background: var(--quote-bg);
}
.markdown-body img { max-width: 100%; border-radius: 6px; }
.markdown-body table { border-collapse: collapse; }
.markdown-body th, .markdown-body td { border: 1px solid var(--border); padding: 6px 12px; }
.markdown-body th { background: var(--code-bg); }
.markdown-body a { color: var(--green-dark); }
.markdown-body hr { border: none; border-top: 1px solid var(--border); }

/* ---------- 정렬 셀렉트 ---------- */
#sort-select {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 4px;
  font-size: 12px;
  background: var(--panel);
  color: var(--text);
}
.new-note-wrap { position: relative; }

/* ---------- 템플릿 메뉴 ---------- */
.template-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 50;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
  min-width: 180px;
  overflow: hidden;
}
.template-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  font-size: 13.5px;
  cursor: pointer;
  white-space: nowrap;
}
.template-item:hover { background: var(--hover); }
.template-item.danger { color: var(--danger); }
.template-item.danger:hover { background: var(--danger-bg); }
.menu-divider { border-top: 1px solid var(--border); margin: 4px 0; }
.nb-menu { top: 100%; right: 8px; }
.nav-item { position: relative; }

/* ---------- 휴지통 ---------- */
.trash-item { cursor: default; }
.trash-actions { margin-top: 7px; display: flex; gap: 6px; }
.mini-btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
}
.mini-btn:hover { background: var(--hover); }
.mini-btn.danger { color: var(--danger); border-color: var(--danger); }
.mini-btn.danger:hover { background: var(--danger-bg); }

/* ---------- 잠긴 노트 ---------- */
.lock-panel {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lock-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(280px, 80vw);
  text-align: center;
}
.lock-icon { font-size: 44px; }
.lock-card p { margin: 0; color: var(--muted); }
.lock-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--list-bg);
  font-size: 15px;
}
.lock-card input:focus { outline: 2px solid var(--green); border-color: transparent; }
.lock-card button {
  width: 100%;
  padding: 9px;
  border: none;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-weight: 600;
}
.lock-card button:hover { background: var(--green-dark); }

/* ---------- 위키링크 자동완성 ---------- */
.wiki-suggest {
  position: absolute;
  left: 20px;
  bottom: 40px;
  z-index: 60;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
  max-width: 320px;
  max-height: 240px;
  overflow-y: auto;
}
.editor-inner { position: relative; }
.wiki-item {
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wiki-item:hover, .wiki-item.sel { background: var(--green); color: #fff; }
.markdown-body a.wikilink { font-weight: 600; text-decoration: none; border-bottom: 1px dashed var(--green-dark); }

/* ---------- 모달 (버전 히스토리) ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-box {
  background: var(--panel);
  border-radius: 12px;
  width: min(720px, 94vw);
  height: min(520px, 88dvh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-body { flex: 1; display: grid; grid-template-columns: 150px 1fr; min-height: 0; }
.history-list { border-right: 1px solid var(--border); overflow-y: auto; }
.history-item {
  padding: 10px 12px;
  font-size: 12.5px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.history-item:hover { background: var(--hover); }
.history-item.sel { background: var(--green); color: #fff; }
.history-item.sel .muted { color: #d8f5de; }
.history-preview { overflow-y: auto; padding: 14px 18px; }
.history-empty { color: var(--muted); font-size: 13px; padding: 14px; text-align: center; line-height: 1.7; }
.modal-foot {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}
.modal-foot button:disabled { opacity: 0.45; cursor: default; }

/* ---------- 검색 하이라이트 ---------- */
mark {
  background: #ffe264;
  color: #2b2b28;
  border-radius: 3px;
  padding: 0 1px;
}
:root[data-theme='dark'] mark { background: #8a6d00; color: #fff; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) mark { background: #8a6d00; color: #fff; }
}

/* ---------- 빠른 전환 (Ctrl+P) ---------- */
.switcher { align-items: flex-start; padding-top: 12vh; }
.switcher-box {
  background: var(--panel);
  border-radius: 12px;
  width: min(520px, 92vw);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}
#switcher-input {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  font-size: 16px;
  background: var(--panel);
}
#switcher-input:focus { outline: none; }
.switcher-list { max-height: 46vh; overflow-y: auto; }
.switcher-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 14px;
}
.switcher-item:hover, .switcher-item.sel { background: var(--green); color: #fff; }
.switcher-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.switcher-meta { font-size: 11.5px; color: var(--muted); flex-shrink: 0; }
.switcher-item.sel .switcher-meta, .switcher-item:hover .switcher-meta { color: #d8f5de; }

/* ---------- 백링크 ---------- */
.backlinks {
  border-top: 1px solid var(--border);
  font-size: 12.5px;
}
.backlinks summary {
  padding: 7px 14px;
  cursor: pointer;
  color: var(--muted);
  user-select: none;
}
.backlink-item { padding: 6px 22px; cursor: pointer; }
.backlink-item:hover { background: var(--hover); }

/* ---------- 더보기 메뉴 ---------- */
.more-wrap { position: relative; }
.more-menu { top: calc(100% + 4px); right: 0; }

/* ---------- 모바일 마크다운 툴바 ---------- */
.md-toolbar {
  display: none;
  gap: 4px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.md-toolbar button {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  min-width: 38px;
  padding: 6px 8px;
  font-size: 14px;
}
.md-toolbar button:active { background: var(--hover); }
@media (max-width: 640px) {
  .md-toolbar { display: flex; }
}

/* ---------- 인쇄: 미리보기만 출력 ---------- */
@media print {
  .sidebar, .notelist, .editor-head, .tags-row, .editor-foot, .md-toolbar,
  .backlinks, #note-body, .toast, .backdrop, #wiki-suggest, .lock-panel,
  .modal, .login { display: none !important; }
  .app { display: block; height: auto; }
  .editor { position: static; display: block; transform: none; }
  .editor-inner { display: block; height: auto; }
  .editor-body { display: block !important; }
  #preview { display: block !important; overflow: visible; padding: 0; }
  html, body { background: #fff; color: #000; height: auto; }
}

/* ---------- 설정 모달 ---------- */
.settings-box { height: auto; max-height: 88dvh; }
.settings-body { padding: 16px 20px; overflow-y: auto; }
.settings-section { margin-bottom: 22px; }
.settings-section h3 { margin: 0 0 6px; font-size: 15px; }
.settings-section p { margin: 4px 0; font-size: 13.5px; }
.settings-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.settings-row input {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 15px;
  width: 140px;
  background: var(--list-bg);
  letter-spacing: 0.2em;
}
.settings-steps { font-size: 13.5px; padding-left: 20px; line-height: 1.8; margin: 6px 0; }
.totp-qr { background: #fff; border-radius: 10px; padding: 8px; display: inline-block; margin: 8px 0; }
.totp-qr svg { display: block; }
.totp-secret { word-break: break-all; }
.totp-secret code { background: var(--code-bg); padding: 2px 6px; border-radius: 4px; font-size: 12px; }

.storage-table { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-top: 6px; }
.storage-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 12px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.storage-row:last-child { border-bottom: none; }
.storage-total { font-weight: 700; background: var(--list-bg); }

.list-sentinel { text-align: center; color: var(--muted); padding: 12px; }

/* ---------- 토스트 ---------- */
.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--toast-bg);
  color: var(--toast-text);
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 13.5px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  z-index: 100;
  max-width: 86vw;
}

.backdrop { display: none; }

/* ---------- 반응형 ---------- */
@media (max-width: 1024px) {
  .app { grid-template-columns: 215px 280px 1fr; }
}

/* 태블릿: 사이드바 오프캔버스 */
@media (max-width: 860px) {
  .app { grid-template-columns: 320px 1fr; }
  .sidebar {
    position: fixed;
    z-index: 40;
    top: 0; bottom: 0; left: 0;
    width: 250px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  body.show-sidebar .sidebar { transform: translateX(0); }
  body.show-sidebar .backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(0, 0, 0, 0.35);
  }
  .hamburger { display: inline-block; }
}

/* 모바일: 목록 ↔ 에디터 단일 패널 전환 */
@media (max-width: 640px) {
  .app { grid-template-columns: 1fr; }
  /* iOS: 입력 필드가 16px 미만이면 포커스 시 자동 줌 → 16px로 고정 */
  .sidebar-search input, #tag-input, .login-card input, #note-body { font-size: 16px; }
  /* 터치 타깃 확대 (44px 권장 근접) */
  .icon-btn { padding: 9px 11px; font-size: 17px; }
  .mode-toggle button { padding: 9px 13px; }
  .new-note-btn { padding: 9px 14px; }
  .editor {
    position: fixed;
    z-index: 20;
    inset: 0;
    transform: translateX(100%);
    transition: transform 0.22s ease;
  }
  body.show-editor .editor { transform: translateX(0); }
  .editor-head { flex-wrap: wrap; }
  .editor-head .back { display: inline-block; }
  /* 모바일에서 분할 모드는 세로 분할 */
  .editor-body.mode-split { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .editor-body.mode-split #note-body { border-right: none; border-bottom: 1px solid var(--border); }
}

/* iOS PWA(홈 화면 설치) 노치/홈바 안전영역 */
@supports (padding: env(safe-area-inset-top)) {
  .sidebar-head { padding-top: calc(14px + env(safe-area-inset-top)); }
  .notelist-head { padding-top: calc(12px + env(safe-area-inset-top)); }
  .editor-head { padding-top: calc(10px + env(safe-area-inset-top)); }
  .sidebar-foot { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .editor-foot { padding-bottom: calc(7px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(26px + env(safe-area-inset-bottom)); }
}
