/* ============================================================
   내 메모장 스타일
   ============================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green: #2f9e44;
  --green-dark: #2b8a3e;
  --bg: #f8f9fa;
  --panel: #fff;          /* 카드/패널 배경 */
  --hover: #e9ecef;       /* 버튼 호버 배경 */
  --border: #dee2e6;
  --border-light: #f1f3f5;
  --active-bg: #ebfbee;   /* 선택된 항목 배경 */
  --toolbar-bg: #fcfcfd;
  --text: #212529;
  --text-dim: #868e96;
  --danger: #e03131;
  --warn-bg: #fff9db;
  --warn-border: #ffe066;
}

/* 다크 모드 (body.dark) */
body.dark {
  --bg: #17181b;
  --panel: #1f2023;
  --hover: #2b2d31;
  --border: #34363c;
  --border-light: #2a2c30;
  --active-bg: #243b2a;
  --toolbar-bg: #1b1c1f;
  --text: #e8eaed;
  --text-dim: #9aa0a6;
  --warn-bg: #3a3320;
  --warn-border: #665c2e;
  color-scheme: dark;
}

html, body { height: 100%; }
body {
  font-family: "Malgun Gothic", "맑은 고딕", "Apple SD Gothic Neo", sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

.hidden { display: none !important; }
button { cursor: pointer; font-family: inherit; }

/* ===== 로딩 ===== */
#loading-screen {
  position: fixed; inset: 0; display: flex;
  align-items: center; justify-content: center; background: var(--bg);
  z-index: 100;
}
.spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 4px solid var(--border); border-top-color: var(--green);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 로그인 ===== */
#login-screen {
  position: fixed; inset: 0; display: flex;
  align-items: center; justify-content: center; background: var(--bg);
}
.login-box {
  width: 320px; padding: 32px 28px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,.06); text-align: center;
}
.login-box h1 { font-size: 24px; margin-bottom: 6px; }
.login-sub { color: var(--text-dim); font-size: 13px; margin-bottom: 24px; }
.primary-btn {
  background: var(--green); color: #fff; border: none;
  padding: 11px 16px; border-radius: 8px; font-size: 14px; font-weight: bold;
}
.primary-btn:hover { background: var(--green-dark); }
.google-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 11px 16px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel); font-size: 14px; font-weight: bold; color: var(--text);
}
.google-btn:hover { background: var(--bg); }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 10px; }

/* ===== 앱 레이아웃 (3단) ===== */
#app { display: flex; height: 100%; }

/* ----- 사이드바 ----- */
#sidebar {
  width: 230px; flex-shrink: 0; background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sidebar-header { padding: 18px 16px 10px; }
.sidebar-header h2 { font-size: 18px; }

#folder-list { list-style: none; overflow-y: auto; flex: 1; padding: 6px 8px; }
#folder-list li {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 10px; border-radius: 8px; font-size: 14px; cursor: pointer;
}
#folder-list li:hover { background: var(--bg); }
#folder-list li.active { background: var(--active-bg); color: var(--green-dark); font-weight: bold; }
#folder-list .folder-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#folder-list .folder-count { font-size: 12px; color: var(--text-dim); }
#folder-list .nav-icon { width: 18px; text-align: center; flex-shrink: 0; }
#folder-list .folder-dot {
  width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; margin: 0 5px 0 4px;
}

/* "폴더" 구역 머리줄 */
#folder-list .folder-section {
  display: flex; align-items: center; gap: 4px;
  margin-top: 8px; padding: 10px 10px 4px;
  border-top: 1px solid var(--border-light);
  color: var(--text-dim); font-size: 12px; cursor: pointer;
}
#folder-list .folder-section:hover { background: none; }
.folder-section-name { flex: 1; font-weight: bold; }
.folder-section-btn {
  border: none; background: none; color: var(--text-dim);
  font-size: 13px; padding: 2px 7px; border-radius: 4px;
}
.folder-section-btn:hover { background: var(--hover); color: var(--text); }

.sidebar-footer {
  padding: 12px 16px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
#user-email { font-size: 12px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; }
#logout-btn {
  border: 1px solid var(--border); background: none; border-radius: 6px;
  padding: 5px 9px; font-size: 12px; color: var(--text-dim); flex-shrink: 0;
}
#logout-btn:hover { color: var(--danger); border-color: var(--danger); }
#theme-btn {
  border: 1px solid var(--border); background: none; border-radius: 6px;
  padding: 4px 8px; font-size: 13px; flex-shrink: 0;
}
#theme-btn:hover { background: var(--hover); }

#sidebar-overlay { display: none; }

/* ----- 메모 목록 ----- */
#list-pane {
  width: 320px; flex-shrink: 0; background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.list-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.list-header h2 { font-size: 16px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#menu-btn {
  border: none; background: none; font-size: 20px; display: none;
}
#new-memo-btn { padding: 8px 12px; font-size: 13px; flex-shrink: 0; }

.search-wrap { padding: 10px 12px; border-bottom: 1px solid var(--border); display: flex; gap: 8px; }
#search-input {
  flex: 1; min-width: 0; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; background: var(--bg);
}
#search-input:focus { outline: 2px solid var(--green); border-color: transparent; }
#sort-select {
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
  font-size: 12px; color: var(--text-dim); padding: 0 4px; max-width: 112px;
}

#memo-list { list-style: none; overflow-y: auto; flex: 1; }
#memo-list li {
  padding: 13px 16px; border-bottom: 1px solid var(--border-light); cursor: pointer;
}
#memo-list li:hover { background: var(--bg); }
#memo-list li.active { background: var(--active-bg); }
.memo-item-title {
  font-size: 16px; font-weight: bold; margin-bottom: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.memo-item-title.untitled { color: var(--text-dim); font-weight: normal; }
.memo-item-snippet {
  font-size: 12px; color: var(--text-dim); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  word-break: break-all;
}
.memo-item-meta { display: flex; gap: 8px; margin-top: 6px; align-items: center; }
.memo-item-date { font-size: 11px; color: #adb5bd; }
.memo-item-folder {
  font-size: 11px; background: var(--hover); color: var(--text-dim);
  padding: 1px 7px; border-radius: 10px;
}
.memo-item-media { font-size: 11px; }
.memo-item-trash { font-size: 11px; color: var(--danger); }
.memo-item-action {
  border: 1px solid var(--border); background: var(--panel); border-radius: 6px;
  padding: 2px 8px; font-size: 11px; color: var(--text-dim);
}
.memo-item-action:hover { color: var(--green-dark); border-color: var(--green); }
.memo-item-action.danger:hover { color: var(--danger); border-color: var(--danger); }
.list-empty { text-align: center; color: var(--text-dim); font-size: 13px; padding: 40px 0; line-height: 1.8; }

/* ----- 편집기 ----- */
#editor-pane { flex: 1; display: flex; flex-direction: column; background: var(--panel); min-width: 0; }
#editor-pane.empty { align-items: center; justify-content: center; background: var(--bg); }
#editor-placeholder { color: var(--text-dim); font-size: 14px; }
#editor-pane:not(.empty) #editor-placeholder { display: none; }

#editor-inner { display: flex; flex-direction: column; height: 100%; min-height: 0; }

.editor-header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
}
#back-btn { border: none; background: none; font-size: 20px; display: none; }
#memo-folder {
  padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px; background: var(--panel); color: var(--text); max-width: 160px;
}
#save-status { flex: 1; font-size: 12px; color: var(--text-dim); text-align: right; }
#star-btn { border: none; background: none; font-size: 17px; opacity: .55; }
#star-btn:hover, #star-btn.starred { opacity: 1; }
#lock-btn { border: none; background: none; font-size: 16px; opacity: .55; }
#lock-btn:hover, #lock-btn.locked { opacity: 1; }
#delete-memo-btn { border: none; background: none; font-size: 17px; opacity: .6; }
#delete-memo-btn:hover { opacity: 1; }

/* 휴지통 메모 안내 배너 */
#trash-banner {
  background: var(--hover); border-bottom: 1px solid var(--border);
  padding: 9px 16px; font-size: 13px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
#trash-banner button {
  border: 1px solid var(--green); color: var(--green-dark); background: var(--panel);
  border-radius: 6px; padding: 4px 12px; font-size: 12px; font-weight: bold;
}
#trash-banner button:hover { background: #ebfbee; }

/* AI 정리 버튼 */
#toolbar button.ai-tidy {
  min-width: auto; padding: 0 10px; font-size: 13px; font-weight: bold;
  color: #6741d9;
}
#toolbar button.ai-tidy:hover { background: #f3f0ff; }
#toolbar button.ai-tidy:disabled { opacity: .6; }

/* AI 정리 후 되돌리기 배너 */
#tidy-banner {
  background: #f3f0ff; border-bottom: 1px solid #d0bfff;
  padding: 9px 16px; font-size: 13px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
#tidy-banner button {
  border: 1px solid #b197fc; color: #6741d9; background: #fff;
  border-radius: 6px; padding: 4px 12px; font-size: 12px; font-weight: bold;
}
#tidy-banner button:hover { background: #f3f0ff; }

/* 중복 경고 배너 */
#dup-warning {
  background: var(--warn-bg); border-bottom: 1px solid var(--warn-border);
  padding: 9px 16px; font-size: 13px; line-height: 1.7;
}
#dup-warning a { color: var(--green-dark); font-weight: bold; margin-right: 10px; }

#memo-title {
  border: none; padding: 16px 20px 8px; font-size: 22px; font-weight: bold;
  outline: none; width: 100%; background: transparent; color: var(--text);
}
#memo-title::placeholder { color: #ced4da; }
body.dark #memo-title::placeholder { color: #5f6368; }

/* 서식 도구막대 */
#toolbar {
  display: flex; align-items: center; gap: 3px; flex-wrap: wrap;
  padding: 6px 14px; border-top: 1px solid var(--border-light); border-bottom: 1px solid var(--border);
  background: var(--toolbar-bg);
}
#toolbar button {
  border: none; background: none; min-width: 32px; height: 32px;
  border-radius: 6px; font-size: 14px; color: #495057;
}
#toolbar button:hover { background: var(--hover); }
.tb-sep { width: 1px; height: 20px; background: var(--border); margin: 0 5px; }
.color-label {
  position: relative; min-width: 32px; height: 32px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: bold; color: var(--danger); cursor: pointer;
}
.color-label.hilite { color: #212529; background: linear-gradient(transparent 55%, #ffe066 55%); }
.color-label:hover { background-color: var(--hover); }
.color-label input[type="color"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%;
}
#font-size {
  border: 1px solid var(--border); border-radius: 6px; padding: 5px;
  font-size: 12px; background: var(--panel); color: var(--text);
}

/* 본문 편집 영역 */
#memo-content {
  flex: 1; overflow-y: auto; padding: 14px 20px 60px;
  font-size: 15px; line-height: 1.8; outline: none; word-break: break-word;
}
#memo-content img, #memo-content video, #memo-content iframe {
  max-width: 100%; border-radius: 8px; margin: 6px 0; display: block; border: none;
}
#memo-content img { cursor: pointer; }
#memo-content img.selected { outline: 2px solid var(--green); outline-offset: 2px; }
#memo-content ul, #memo-content ol { padding-left: 26px; }

/* 체크리스트 (할 일) */
.todo-line { display: flex; align-items: flex-start; gap: 8px; margin: 2px 0; }
.todo-check {
  width: 17px; height: 17px; margin-top: 5px; flex-shrink: 0;
  accent-color: var(--green); cursor: pointer;
}
.todo-line:has(.todo-check:checked) {
  color: var(--text-dim); text-decoration: line-through;
}

/* 링크 미리보기 카드 */
#memo-content .link-card {
  display: block; max-width: 460px; text-decoration: none; color: inherit;
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 14px; margin: 8px 0; background: var(--bg); cursor: pointer;
}
#memo-content .link-card:hover { border-color: var(--green); background: var(--hover); }
.link-card-title {
  display: block; font-weight: bold; font-size: 14px; color: var(--text); margin-bottom: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.link-card-desc {
  font-size: 12px; color: var(--text-dim); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.link-card-url { display: block; font-size: 11px; color: var(--green-dark); margin-top: 6px; }

/* 사진 선택 시 뜨는 크기 조절 도구막대 + 모서리 핸들 */
#img-tools {
  position: fixed; z-index: 60; display: none; gap: 2px; align-items: center;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,.15); padding: 4px;
}
#img-tools button {
  border: none; background: none; padding: 5px 9px; border-radius: 6px;
  font-size: 12px; color: #495057;
}
#img-tools button:hover { background: var(--hover); }
#img-tools button[data-del] { color: var(--danger); }
#img-resize-handle {
  position: fixed; z-index: 61; display: none; width: 14px; height: 14px;
  background: var(--green); border: 2px solid #fff; border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0,0,0,.3); cursor: nwse-resize; touch-action: none;
}

.editor-footer {
  padding: 8px 20px; border-top: 1px solid var(--border-light);
  font-size: 12px; color: #adb5bd;
}

/* ===== 대화상자 (확인/입력/알림) ===== */
#dialog-overlay {
  position: fixed; inset: 0; z-index: 90; display: none;
  align-items: center; justify-content: center; background: rgba(0,0,0,.35);
}
#dialog-box {
  width: 320px; max-width: calc(100% - 40px); background: var(--panel);
  border-radius: 12px; padding: 20px; box-shadow: 0 8px 30px rgba(0,0,0,.2);
}
#dialog-msg { font-size: 14px; line-height: 1.6; white-space: pre-line; margin-bottom: 14px; }
#dialog-input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; margin-bottom: 14px;
}
#dialog-input:focus { outline: 2px solid var(--green); border-color: transparent; }
#dialog-btns { display: flex; justify-content: flex-end; gap: 8px; }
#dialog-btns button { padding: 8px 16px; border-radius: 8px; font-size: 13px; }
#dialog-cancel { border: 1px solid var(--border); background: var(--panel); color: var(--text-dim); }
#dialog-cancel:hover { background: var(--bg); }
#dialog-ok { border: none; background: var(--green); color: #fff; font-weight: bold; }
#dialog-ok:hover { background: var(--green-dark); }

/* ===== 선택 메뉴 (폴더 이름변경/삭제 등) ===== */
#sheet-overlay {
  position: fixed; inset: 0; z-index: 90; display: none;
  align-items: center; justify-content: center; background: rgba(0,0,0,.35);
}
#sheet-box {
  width: 260px; max-width: calc(100% - 40px); background: var(--panel);
  border-radius: 12px; padding: 16px; box-shadow: 0 8px 30px rgba(0,0,0,.2);
}
#sheet-title {
  font-size: 14px; font-weight: bold; text-align: center; margin-bottom: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#sheet-btns { display: flex; flex-direction: column; gap: 6px; }
#sheet-btns button {
  padding: 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel); font-size: 14px; color: var(--text);
}
#sheet-btns button:hover { background: var(--bg); }
#sheet-btns button.danger { color: var(--danger); }
#sheet-btns button.cancel { border: none; color: var(--text-dim); }

/* ===== 다크 모드 세부 보정 ===== */
body.dark #search-input, body.dark #dialog-input { color: var(--text); }
body.dark #toolbar button, body.dark #img-tools button { color: #ced4da; }
body.dark #folder-list li.active { color: #69db7c; }
body.dark #dup-warning a { color: #8ce99a; }
body.dark #trash-banner button { background: transparent; color: #8ce99a; }
body.dark #tidy-banner { background: #2a2440; border-color: #4a3f73; }
body.dark #tidy-banner button { background: transparent; color: #b197fc; border-color: #6741d9; }
body.dark #toolbar button.ai-tidy { color: #b197fc; }
body.dark #toolbar button.ai-tidy:hover { background: #2a2440; }
body.dark .memo-item-action:hover { color: #8ce99a; }
body.dark .memo-item-date, body.dark .editor-footer { color: var(--text-dim); }

/* ===== 모바일 (768px 이하) ===== */
@media (max-width: 768px) {
  /* 사이드바: 햄버거 메뉴로 슬라이드 */
  #sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 30;
    transform: translateX(-100%); transition: transform .2s;
    box-shadow: 4px 0 16px rgba(0,0,0,.1);
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 20;
  }
  #sidebar-overlay.show { display: block; }
  #menu-btn { display: block; }

  /* 목록과 편집기는 한 화면씩 */
  #list-pane { width: 100%; border-right: none; }
  #editor-pane {
    position: fixed; inset: 0; z-index: 10;
    transform: translateX(100%); transition: transform .2s;
  }
  body.show-editor #editor-pane { transform: translateX(0); }
  #editor-pane.empty { display: none; }
  #back-btn { display: block; }

  #memo-title { font-size: 19px; }
  /* 폰: 버튼이 한 줄에 다 안 들어가면 여러 줄로 자동 줄바꿈 */
  #toolbar { overflow-x: visible; flex-wrap: wrap; row-gap: 6px; padding: 8px 12px; }
  #toolbar button, .color-label { min-width: 34px; height: 34px; }
  .tb-sep { margin: 0 3px; }
}
