/* 메모 페이지(memo.html) 전용 라이트 테마. 다른 페이지 CSS와 완전히 독립. */

.memo-page {
    --memo-bg: #ffffff;
    --memo-bg-alt: #eef1f6;
    --memo-bg-hover: #e2e8f0;
    --memo-border: #e2e8f0;
    --memo-text: #1e293b;
    --memo-text-strong: #0f172a;
    --memo-muted: #64748b;
    /* #ffffff 배경에서 WCAG AA(4.5:1)를 넘는 최소한의 흐린 텍스트 색. */
    --memo-faint: #6b7280;
    --memo-accent: #5b4bd6;
    --memo-accent-soft: rgba(91, 75, 214, 0.12);
    --memo-danger: #dc2626;
    --memo-code-bg: #f1f3f6;
    --memo-radius: 8px;

    color-scheme: light;
    margin: 0;
    min-height: 100vh;
    background: var(--memo-bg);
    color: var(--memo-text);
    font-family: "Pretendard Variable", Pretendard, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.6;
}

.memo-page *,
.memo-page *::before,
.memo-page *::after {
    box-sizing: border-box;
}

/* ---- 로딩/오류 화면 ---- */

.memo-loading {
    display: grid;
    place-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    color: var(--memo-muted);
    font-size: 14px;
}

.memo-loading[hidden],
html.tt-memo-guest .memo-loading,
html.tt-memo-fatal .memo-loading {
    display: none;
}

.memo-fatal {
    display: grid;
    place-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 24px;
    text-align: center;
}

.memo-fatal[hidden] {
    display: none;
}

.memo-fatal h1 {
    margin: 0 0 8px;
    font-size: 22px;
    color: var(--memo-text-strong);
}

.memo-fatal p {
    margin: 0;
    color: var(--memo-muted);
    font-size: 14px;
}

html.tt-memo-fatal .memo-auth-gate,
html.tt-memo-fatal .memo-shell {
    display: none !important;
}

/* ---- 인증 게이트: pre-paint에는 tt-memo-guest 클래스로, 이후엔 JS가 소유 ---- */

.memo-auth-gate {
    display: none;
    min-height: 100vh;
    place-items: center;
    padding: 24px;
    text-align: center;
}

html.tt-memo-guest .memo-auth-gate {
    display: grid;
}

html.tt-memo-guest .memo-shell {
    display: none !important;
}

html.tt-memo-guest .memo-fatal {
    display: none;
}

.memo-auth-gate h1 {
    margin: 0 0 8px;
    font-size: 26px;
    color: var(--memo-text-strong);
}

.memo-auth-gate p {
    margin: 0 0 20px;
    color: var(--memo-muted);
    font-size: 14px;
}

.memo-auth-gate-login {
    display: inline-block;
    padding: 11px 22px;
    border-radius: 6px;
    background: var(--memo-accent);
    color: #fff;
    font-weight: 700;
    text-decoration: none;
}

/* ---- 관리자 전용 게이트: 세션은 있지만 관리자가 아닌 계정 (memo/memo-app.js) ---- */

.memo-denied {
    display: none;
    min-height: 100vh;
    place-items: center;
    padding: 24px;
    text-align: center;
}

html.tt-memo-denied .memo-denied {
    display: grid;
}

html.tt-memo-denied .memo-loading,
html.tt-memo-denied .memo-auth-gate,
html.tt-memo-denied .memo-fatal {
    display: none;
}

html.tt-memo-denied .memo-shell {
    display: none !important;
}

.memo-denied h1 {
    margin: 0 0 8px;
    font-size: 26px;
    color: var(--memo-text-strong);
}

.memo-denied p {
    margin: 0 0 20px;
    color: var(--memo-muted);
    font-size: 14px;
}

.memo-denied-home {
    display: inline-block;
    padding: 11px 22px;
    border-radius: 6px;
    background: var(--memo-accent);
    color: #fff;
    font-weight: 700;
    text-decoration: none;
}

/* ---- 레이아웃 ---- */

.memo-shell {
    display: grid;
    grid-template-columns: 260px 1fr;
    height: 100vh;
    /* 모바일 브라우저 UI에 하단이 잘리지 않게 동적 뷰포트 사용. */
    height: 100dvh;
    overflow: hidden;
}

.memo-shell[hidden] {
    display: none;
}

/* ---- 사이드바 ---- */

.memo-sidebar {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--memo-bg-alt);
    border-right: 1px solid var(--memo-border);
}

/* 버튼(드라이브·새 폴더·＋ 새 메모)이 260px 폭에 한 줄로 안 들어가면 줄을 바꿔 오른쪽에
   붙인다 — 사이드바 밖으로 넘쳐 본문 헤더를 가리지 않게. */
.memo-sidebar-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 12px 8px;
}

.memo-home-link {
    color: var(--memo-muted);
    font-size: 13px;
    text-decoration: none;
    white-space: nowrap;
}

.memo-home-link:hover {
    color: var(--memo-text);
}

.memo-new-note {
    border: 0;
    border-radius: 6px;
    padding: 6px 10px;
    background: var(--memo-accent);
    color: #fff;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

.memo-sidebar-head-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    margin-left: auto;
}

.memo-new-folder {
    border: 1px solid var(--memo-border);
    border-radius: 6px;
    padding: 6px 9px;
    background: none;
    color: var(--memo-muted);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}

.memo-new-folder:hover {
    color: var(--memo-text);
    border-color: var(--memo-muted);
}

.memo-drive-btn {
    border: 1px solid var(--memo-border);
    border-radius: 6px;
    padding: 6px 9px;
    background: none;
    color: var(--memo-muted);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}

.memo-drive-btn:hover {
    color: var(--memo-text);
    border-color: var(--memo-muted);
}

/* 연결된 상태는 강조색 테두리로만 표시 — 사이드바가 시끄러워지지 않게. */
.memo-drive-btn.is-connected {
    color: var(--memo-accent);
    border-color: var(--memo-accent);
}

.memo-search {
    margin: 0 12px 8px;
    padding: 7px 10px;
    border: 1px solid var(--memo-border);
    border-radius: 6px;
    background: var(--memo-bg);
    color: var(--memo-text);
    font: inherit;
    font-size: 13px;
}

.memo-search:focus {
    outline: none;
    border-color: var(--memo-accent);
}

.memo-note-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0 6px 12px;
}

.memo-folder-group + .memo-folder-group {
    margin-top: 2px;
}

/* 폴더 줄 = 토글(접기/펴기) + 개수 + ＋(이 폴더에 새 메모) + ⋯(폴더 메뉴).
   토글의 텍스트는 폴더 이름만이다(캐럿은 ::before) — 테스트가 이름을 그대로 읽는다. */
.memo-folder-row {
    display: flex;
    align-items: center;
    gap: 2px;
    padding-right: 4px;
    border-radius: 6px;
}

.memo-folder-row:hover {
    background: var(--memo-bg-hover);
}

.memo-folder-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
    border: 0;
    background: none;
    padding: 6px 8px;
    color: var(--memo-muted);
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.02em;
    cursor: pointer;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    /* 롱프레스로 폴더 메뉴를 연다 — iOS의 기본 선택/콜아웃이 끼어들지 않게. */
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
}

.memo-folder-toggle::before {
    content: '▾';
    flex-shrink: 0;
    font-size: 10px;
    transition: transform 0.12s ease;
}

.memo-folder-group.is-collapsed .memo-folder-toggle::before {
    transform: rotate(-90deg);
}

.memo-folder-group.is-collapsed .memo-folder-notes {
    display: none;
}

.memo-folder-count {
    flex-shrink: 0;
    color: var(--memo-faint);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}

/* ＋/⋯은 마우스를 올리거나 키보드 포커스가 줄 안에 있을 때만 드러난다. display가 아니라
   opacity라 탭 순서에는 항상 남아 있다. 호버가 없는 터치 화면에서는 늘 보인다. */
.memo-folder-add,
.memo-folder-more {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border: 0;
    border-radius: 5px;
    background: none;
    color: var(--memo-muted);
    font: inherit;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s ease;
}

.memo-folder-row:hover .memo-folder-add,
.memo-folder-row:hover .memo-folder-more,
.memo-folder-row:focus-within .memo-folder-add,
.memo-folder-row:focus-within .memo-folder-more {
    opacity: 1;
}

.memo-folder-add:hover,
.memo-folder-more:hover {
    background: var(--memo-accent-soft);
    color: var(--memo-accent);
}

@media (hover: none) {
    .memo-folder-add,
    .memo-folder-more {
        opacity: 1;
    }
}

.memo-note-item {
    display: block;
    width: 100%;
    border: 0;
    border-radius: 6px;
    background: none;
    padding: 6px 10px;
    color: var(--memo-text);
    font: inherit;
    font-size: 13.5px;
    text-align: left;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    /* 롱프레스로 노트 메뉴를 연다 — iOS 콜아웃·텍스트 선택이 끼어들지 않게. */
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
}

/* 폴더 안의 노트는 한 단 들여 써서 폴더 줄과 구분한다. */
.memo-folder-notes .memo-note-item {
    padding-left: 24px;
}

.memo-note-item:hover {
    background: var(--memo-bg-hover);
}

.memo-note-item.is-active {
    background: var(--memo-accent-soft);
    color: var(--memo-text-strong);
    box-shadow: inset 2px 0 0 var(--memo-accent);
}

/* 폴더 없는 노트는 그룹 헤더 없이 바로 나열한다(옵시디언식). 앞에 폴더 그룹이 있으면
   실선 하나로만 나눈다 — "메모"라는 가짜 헤더가 실제 "메모" 폴더와 충돌하던 문제의 해법. */
.memo-root-notes {
    padding-top: 2px;
}

.memo-folder-group + .memo-root-notes {
    margin-top: 6px;
    padding-top: 8px;
    border-top: 1px solid var(--memo-border);
}

.memo-list-empty {
    padding: 18px 16px;
    color: var(--memo-faint);
    font-size: 13px;
    text-align: center;
}

/* ---- 에디터 영역 ---- */

.memo-main {
    display: flex;
    flex-direction: column;
    position: relative;
    min-width: 0;
    min-height: 0;
}

.memo-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 20px;
    background: rgba(220, 38, 38, 0.10);
    color: #b02525;
    font-size: 13px;
}

.memo-banner[hidden] {
    display: none;
}

.memo-banner-retry {
    border: 1px solid currentColor;
    border-radius: 5px;
    background: none;
    padding: 3px 10px;
    color: inherit;
    font: inherit;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}

/* 세션 만료 안내: 셸 위에 얹혀 내용은 계속 보이고 복사도 가능하게 유지한다. */
.memo-session-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 10px 20px;
    background: rgba(240, 180, 60, 0.22);
    color: #8a6100;
    font-size: 13px;
}

.memo-session-bar a {
    color: inherit;
    font-weight: 700;
}

.memo-session-bar button {
    border: 1px solid currentColor;
    border-radius: 5px;
    background: none;
    padding: 3px 10px;
    color: inherit;
    font: inherit;
    font-size: 12px;
    cursor: pointer;
}

/* 노트 헤더는 두 줄: [폴더 칩 … 저장 상태] / [제목 … 주석 복사 첨부 삭제]. */
.memo-note-head {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 12px 20px 6px;
}

.memo-note-head[hidden] {
    display: none;
}

.memo-note-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 24px;
}

.memo-folder-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    max-width: min(60vw, 420px);
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 2px 9px 2px 7px;
    background: none;
    color: var(--memo-muted);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.memo-folder-chip::before {
    content: '▸';
    flex-shrink: 0;
    font-size: 10px;
    color: var(--memo-faint);
}

.memo-folder-chip:hover,
.memo-folder-chip:focus-visible {
    color: var(--memo-text);
    border-color: var(--memo-border);
    background: var(--memo-bg-alt);
    outline: none;
}

.memo-note-titlebar {
    display: flex;
    align-items: center;
    gap: 12px;
}

.memo-title-input {
    flex: 1;
    min-width: 0;
    border: 0;
    background: none;
    color: var(--memo-text-strong);
    font: inherit;
    font-size: 24px;
    font-weight: 700;
}

.memo-title-input:focus {
    outline: none;
}

.memo-title-input.is-invalid {
    color: var(--memo-danger);
}

.memo-note-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.memo-note-actions button {
    border: 1px solid var(--memo-border);
    border-radius: 6px;
    background: none;
    padding: 5px 10px;
    color: var(--memo-muted);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
}

.memo-note-actions button:hover {
    color: var(--memo-text);
    border-color: var(--memo-muted);
}

.memo-copy-btn {
    /* 복사 → 복사됨으로 라벨이 바뀌어도 툴바가 흔들리지 않게 폭을 잡아 둔다. */
    min-width: 52px;
}

.memo-copy-btn.is-copied {
    color: var(--memo-accent);
    border-color: var(--memo-accent);
}

.memo-note-actions .memo-danger:hover {
    color: var(--memo-danger);
    border-color: var(--memo-danger);
}

.memo-save-state {
    color: var(--memo-faint);
    font-size: 12px;
    white-space: nowrap;
}

.memo-editor-host {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.memo-editor-host[hidden] {
    display: none;
}

.memo-editor-empty {
    flex: 1;
    display: grid;
    place-items: center;
    color: var(--memo-faint);
    font-size: 14px;
    text-align: center;
}

.memo-editor-empty[hidden] {
    display: none;
}

.memo-editor-empty p {
    margin: 0 0 14px;
}

.memo-empty-attach {
    border: 1px solid var(--memo-border);
    border-radius: 7px;
    background: var(--memo-bg-alt);
    padding: 8px 12px;
    color: var(--memo-text);
    font: inherit;
    cursor: pointer;
}

.memo-empty-attach:hover {
    border-color: var(--memo-accent);
    color: var(--memo-accent);
}

.memo-empty-drop-hint {
    margin: 8px 0 0 !important;
    font-size: 12px;
}

.memo-drop-overlay {
    position: absolute;
    inset: 12px;
    z-index: 18;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 6px;
    border: 2px dashed var(--memo-accent);
    border-radius: 12px;
    background: rgba(239, 246, 255, 0.94);
    color: var(--memo-accent);
    pointer-events: none;
}

.memo-drop-overlay strong {
    font-size: 18px;
}

.memo-drop-overlay span {
    color: var(--memo-muted);
    font-size: 13px;
}

.memo-main.is-file-dragging .memo-drop-overlay {
    display: flex;
}

/* ---- CodeMirror 테마 ---- */

.memo-editor-host .cm-editor {
    flex: 1;
    min-height: 0;
    background: var(--memo-bg);
    color: var(--memo-text);
    font-size: 15px;
}

.memo-editor-host .cm-editor.cm-focused {
    outline: none;
}

.memo-editor-host .cm-scroller {
    font-family: inherit;
    line-height: 1.7;
    padding: 8px 20px 40vh;
}

.memo-editor-host .cm-content {
    max-width: 760px;
    margin: 0 auto;
    caret-color: var(--memo-accent);
}

.memo-editor-host .cm-cursor {
    border-left-color: var(--memo-accent);
}

.memo-editor-host .cm-selectionBackground,
.memo-editor-host .cm-editor ::selection {
    background: rgba(91, 75, 214, 0.18);
}

.memo-editor-host .cm-placeholder {
    color: var(--memo-faint);
}

/* ---- 라이브 프리뷰 마크다운 스타일 ---- */

.memo-md-h1, .memo-md-h2, .memo-md-h3,
.memo-md-h4, .memo-md-h5, .memo-md-h6 {
    color: var(--memo-text-strong);
    font-weight: 700;
}

.memo-md-h1 { font-size: 1.7em; line-height: 1.4; }
.memo-md-h2 { font-size: 1.45em; line-height: 1.4; }
.memo-md-h3 { font-size: 1.25em; line-height: 1.4; }
.memo-md-h4 { font-size: 1.1em; }
.memo-md-h5 { font-size: 1em; }
.memo-md-h6 { font-size: 0.95em; color: var(--memo-muted); }

.memo-md-strong { font-weight: 700; color: var(--memo-text-strong); }
.memo-md-em { font-style: italic; }
.memo-md-strike { text-decoration: line-through; color: var(--memo-muted); }

.memo-md-code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.88em;
    background: var(--memo-code-bg);
    border-radius: 4px;
    padding: 1px 4px;
}

.memo-md-codeblock {
    background: var(--memo-code-bg);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.88em;
}

.memo-md-codefence {
    color: var(--memo-faint);
}

.memo-md-quote {
    border-left: 3px solid var(--memo-accent);
    padding-left: 12px;
    color: var(--memo-muted);
}

.memo-md-listmark {
    color: var(--memo-accent);
}

.memo-md-task-checkbox {
    accent-color: var(--memo-accent);
    margin: 0 6px 0 0;
    vertical-align: middle;
    cursor: pointer;
}

/* 마크다운 링크와 자동 링크(맨 URL·메일). 자동 링크는 감추면 글자가 통째로
   사라지므로 원문을 그대로 두고 색과 밑줄로만 링크임을 알린다. */
.memo-md-link {
    color: var(--memo-accent);
    text-decoration: underline;
    text-decoration-color: var(--memo-accent-soft);
    text-underline-offset: 2px;
    cursor: pointer;
}

.memo-md-link:hover {
    text-decoration-color: var(--memo-accent);
}

.memo-md-wikilink {
    color: var(--memo-accent);
    cursor: pointer;
}

.memo-md-wikilink:hover {
    text-decoration: underline;
}

.memo-md-wikilink-unresolved {
    color: var(--memo-muted);
    text-decoration: underline dotted;
}

.memo-md-hr {
    border: 0;
    border-top: 1px solid var(--memo-border);
    margin: 0.4em 0;
}

/* ---- 문구 주석(어노테이션): ==문구==%%주석%% ---- */

/* 주석 달린 문구: 하늘색 형광펜 하이라이트. 문법(== / %%주석%%)은 커서가 그 줄에
   있어도 드러나지 않는다 — 클릭하면 팝오버로 주석을 보여준다. */
.memo-md-annotation {
    background: rgba(125, 211, 252, 0.4);
    border-bottom: 1px dashed rgba(2, 132, 199, 0.55);
    border-radius: 2px;
    cursor: pointer;
}

.memo-md-annotation:hover {
    background: rgba(125, 211, 252, 0.62);
}

/* 선택 위에 뜨는 "주석 달기" 플로팅 버튼. */
.memo-annotation-add-btn {
    position: fixed;
    z-index: 22;
    padding: 5px 12px;
    border: 1px solid var(--memo-border);
    border-radius: 999px;
    background: var(--memo-bg);
    color: var(--memo-accent);
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.16);
    cursor: pointer;
}

.memo-annotation-add-btn:hover,
.memo-annotation-add-btn:focus-visible {
    background: var(--memo-bg-hover);
}

/* 하이라이트 클릭 시 뜨는 주석 팝오버. */
.memo-annotation-popover {
    position: fixed;
    z-index: 22;
    width: max-content;
    max-width: min(88vw, 320px);
    padding: 10px 12px;
    border: 1px solid var(--memo-border);
    border-radius: var(--memo-radius);
    background: var(--memo-bg);
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.16);
}

.memo-annotation-popover-note {
    margin: 0 0 8px;
    color: var(--memo-text);
    font-size: 13px;
    line-height: 1.5;
    word-break: break-word;
}

.memo-annotation-popover-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

.memo-annotation-popover-actions button {
    border: 1px solid var(--memo-border);
    border-radius: 6px;
    background: none;
    padding: 4px 10px;
    color: var(--memo-text);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
}

.memo-annotation-popover-actions button:hover,
.memo-annotation-popover-actions button:focus-visible {
    background: var(--memo-bg-hover);
    outline: none;
}

.memo-annotation-popover-actions .memo-annotation-popover-danger {
    color: var(--memo-danger);
}

/* ---- 표 ----
   커서가 표 밖에 있으면 원문 전체가 진짜 <table> 위젯으로 바뀐다. 칸을 누르면
   그 자리에 캐럿이 놓이며 원문(아래 -source)으로 되돌아간다. */

.memo-md-table-wrap {
    /* 칸이 많은 표는 본문 폭을 밀어내지 않고 표 안에서 가로로 넘긴다. */
    overflow-x: auto;
    margin: 0.35em 0;
}

.memo-md-table {
    border-collapse: collapse;
    /* 내용만큼만 넓히되 좁은 표가 늘어지지 않게. */
    width: auto;
    max-width: 100%;
    font-size: 0.95em;
    line-height: 1.5;
}

.memo-md-table th,
.memo-md-table td {
    border: 1px solid var(--memo-border);
    padding: 5px 10px;
    text-align: left;
    vertical-align: top;
    /* 빈 칸도 눌러 캐럿을 놓을 수 있게 최소 폭을 준다. */
    min-width: 2em;
    cursor: text;
}

.memo-md-table th {
    background: var(--memo-code-bg);
    color: var(--memo-text-strong);
    font-weight: 700;
}

.memo-md-table .is-align-center { text-align: center; }
.memo-md-table .is-align-right { text-align: right; }
.memo-md-table .is-align-left { text-align: left; }

/* 표를 고치는 동안(커서가 표 안) 보이는 원문. 파이프가 세로로 맞아야 어느 칸을
   고치는지 눈에 들어오므로 고정폭으로 둔다. */
.memo-md-table-source {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.88em;
    background: var(--memo-code-bg);
}

/* ---- 첨부(구글드라이브) ---- */

.memo-attach-input {
    display: none;
}

.memo-md-image-wrap {
    position: relative;
    display: block;
    width: fit-content;
    max-width: 100%;
    margin: 4px 0;
}

.memo-md-image {
    display: block;
    max-width: 100%;
    /* 이미지가 도착하기 전 자리를 잡아 본문이 튀지 않게. */
    min-height: 24px;
    border-radius: var(--memo-radius);
    margin: 0;
}

.memo-md-image.is-broken {
    min-height: 40px;
    padding: 10px 12px;
    border: 1px dashed var(--memo-border);
    color: var(--memo-faint);
    font-size: 13px;
}

.memo-md-image-download {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.72);
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.76);
    color: #fff;
    font: 700 19px/1 system-ui, sans-serif;
    cursor: pointer;
    opacity: 0;
    transform: translateY(-2px);
    transition: opacity 120ms ease, transform 120ms ease, background 120ms ease;
}

.memo-md-image-wrap:hover .memo-md-image-download,
.memo-md-image-download:focus-visible {
    opacity: 1;
    transform: translateY(0);
}

.memo-md-image-download:hover,
.memo-md-image-download:focus-visible {
    background: rgba(15, 23, 42, 0.92);
}

@media (hover: none) {
    .memo-md-image-download {
        opacity: 1;
        transform: none;
    }
}

/* 첨부 파일 링크: 본문 속에서 눌러 내려받는 칩. */
/* 파일명은 본문 글자다 — 눌러도 받아지지 않고 캐럿만 놓인다(줄 나누기 가능).
   내려받기는 앞의 형식 아이콘 몫이라 커서 모양도 글자로 둔다. */
.memo-md-attach {
    color: var(--memo-accent);
    border-bottom: 1px solid var(--memo-accent-soft);
    cursor: text;
}

.memo-md-attach:hover {
    border-bottom-color: var(--memo-accent);
}

/* 파일 형식 아이콘: 파일명 앞에 붙어 종류를 한눈에 알려주고, 첨부를 내려받는
   버튼 노릇도 한다. 커서가 그 줄에 없을 때(원문 숨김 상태)만 그려진다.
   손가락으로도 누를 수 있게 히트 영역을 세로로만 넓힌다 — 가로로 넓히면 옆
   파일명 글자를 덮어 캐럿을 놓으려던 클릭이 다시 다운로드가 된다.
   전역 border-box라 padding이 아이콘을 줄이므로 content-box로 되돌린다. */
.memo-md-attach-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: content-box;
    width: 1.15em;
    height: 1.15em;
    padding: 0.3em 0.06em;
    margin: -0.3em 0.18em -0.3em -0.06em;
    vertical-align: -0.2em;
    color: var(--memo-file-icon, var(--memo-muted));
    cursor: pointer;
}

.memo-md-attach-icon svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* 색도 Office 관례를 따른다 — 워드 파랑 / 엑셀 초록 / 파워포인트 주황.
   나머지 갈래는 그 셋과 헷갈리지 않는 색으로 배치한다. */
.memo-md-attach-icon-doc { --memo-file-icon: #2b579a; }
.memo-md-attach-icon-sheet { --memo-file-icon: #217346; }
.memo-md-attach-icon-slide { --memo-file-icon: #d24726; }
.memo-md-attach-icon-pdf { --memo-file-icon: #c1121f; }
.memo-md-attach-icon-image { --memo-file-icon: #7048b6; }
.memo-md-attach-icon-video { --memo-file-icon: #bc1948; }
.memo-md-attach-icon-audio { --memo-file-icon: #4338ca; }
.memo-md-attach-icon-archive { --memo-file-icon: #a65b0b; }
.memo-md-attach-icon-code { --memo-file-icon: #0e7490; }
.memo-md-attach-icon-text { --memo-file-icon: #5b6472; }
.memo-md-attach-icon-file { --memo-file-icon: #6b7280; }

/* 파일명 뒤 크기 표시. 감춘 "](ttfile:…)" 자리를 대신 차지하므로 본문 글자처럼
   보이지 않게 작고 흐리게 둔다 — 정보는 주되 문장을 어지럽히지 않는다. */
.memo-md-attach-meta {
    color: var(--memo-faint);
    font-size: 0.82em;
    user-select: none;
}

/* ---- 첨부함 (첨부 파일 정보 + 삭제) ---- */

/* 툴바 배지: 첨부 개수. 본문에서 지운 첨부가 드라이브에 남아 있으면 경고색. */
.memo-attach-count {
    display: inline-block;
    margin-left: 5px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--memo-accent-soft);
    color: var(--memo-accent);
    font-size: 11px;
    font-weight: 700;
    line-height: 1.6;
    vertical-align: 1px;
}

.memo-attach-list-btn.has-orphan .memo-attach-count {
    background: rgba(220, 38, 38, 0.12);
    color: var(--memo-danger);
}

.memo-attach-box {
    width: min(94vw, 460px);
}

.memo-attach-hint {
    margin: 0 0 12px;
}

.memo-attach-list {
    display: grid;
    gap: 8px;
    max-height: min(52vh, 420px);
    overflow-y: auto;
    margin-bottom: 14px;
}

.memo-attach-item {
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--memo-border);
    border-radius: var(--memo-radius);
    padding: 8px 10px;
}

.memo-attach-item.is-orphan {
    border-color: rgba(220, 38, 38, 0.35);
}

.memo-attach-item-icon {
    flex: none;
    width: 20px;
    height: 20px;
    color: var(--memo-file-icon, var(--memo-muted));
}

.memo-attach-item-icon svg {
    width: 100%;
    height: 100%;
    display: block;
}

.memo-attach-item-body {
    flex: 1;
    min-width: 0;
}

.memo-attach-item-name {
    display: block;
    color: var(--memo-text-strong);
    font-size: 13px;
    word-break: break-all;
}

.memo-attach-item-meta {
    display: block;
    color: var(--memo-faint);
    font-size: 12px;
}

.memo-attach-item-flag {
    display: inline-block;
    margin-top: 3px;
    padding: 0 6px;
    border-radius: 999px;
    background: rgba(220, 38, 38, 0.12);
    color: var(--memo-danger);
    font-size: 11px;
    line-height: 1.7;
}

.memo-attach-item-actions {
    display: flex;
    flex: none;
    align-items: center;
    gap: 6px;
}

.memo-attach-item-actions button,
.memo-attach-item-actions .memo-attach-item-link {
    border: 1px solid var(--memo-border);
    border-radius: 6px;
    background: none;
    padding: 3px 9px;
    color: var(--memo-text);
    font: inherit;
    font-size: 12px;
    text-decoration: none;
    cursor: pointer;
}

.memo-attach-item-actions button:hover,
.memo-attach-item-actions button:focus-visible,
.memo-attach-item-actions .memo-attach-item-link:hover,
.memo-attach-item-actions .memo-attach-item-link:focus-visible {
    background: var(--memo-bg-hover);
    outline: none;
}

.memo-attach-item-actions .memo-attach-item-danger {
    color: var(--memo-danger);
}

/* 정리 버튼은 왼쪽 끝, 닫기는 오른쪽 끝. */
.memo-attach-actions {
    justify-content: space-between;
}

.memo-attach-actions button[hidden] {
    display: none;
}

/* 모달 체크박스(예: 메모와 함께 첨부까지 삭제). 전역 .memo-modal input 규칙이
   가로 폭을 100%로 늘려 놓으므로 여기서 되돌린다. */
.memo-modal-check {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: -4px 0 14px;
    color: var(--memo-text);
    font-size: 13px;
    cursor: pointer;
}

.memo-modal-check input[type="checkbox"] {
    width: auto;
    margin: 0;
    flex: none;
}

/* ---- 폴더 컨텍스트 메뉴 (우클릭 / 롱프레스) ---- */

.memo-context-menu {
    position: fixed;
    z-index: 22;
    min-width: 150px;
    padding: 4px;
    border: 1px solid var(--memo-border);
    border-radius: var(--memo-radius);
    background: var(--memo-bg);
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.16);
}

.memo-context-menu button {
    display: block;
    width: 100%;
    border: 0;
    border-radius: 5px;
    background: none;
    padding: 9px 12px;
    color: var(--memo-text);
    font: inherit;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.memo-context-menu button:hover,
.memo-context-menu button:focus-visible {
    background: var(--memo-bg-hover);
    outline: none;
}

.memo-context-menu hr {
    margin: 4px 0;
    border: 0;
    border-top: 1px solid var(--memo-border);
}

.memo-context-menu .memo-danger {
    color: var(--memo-danger);
}

/* 폴더 선택기: 같은 메뉴 크롬에 라디오 항목(현재 폴더 ✓)만 얹는다. 폴더가 많으면 스크롤. */
.memo-context-menu [role="menuitemradio"] {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.memo-context-menu [role="menuitemradio"][aria-checked="true"] {
    color: var(--memo-accent);
    font-weight: 700;
}

.memo-context-menu [role="menuitemradio"][aria-checked="true"]::after {
    content: '✓';
    font-size: 12px;
}

.memo-folder-picker {
    min-width: 220px;
    max-width: min(92vw, 360px);
    max-height: 60vh;
    overflow-y: auto;
}

.memo-folder-picker [role="menuitemradio"] {
    overflow: hidden;
}

.memo-folder-picker [role="menuitemradio"] span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- 폴더 이동/삭제 확인 모달 ---- */

.memo-modal-backdrop {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(15, 23, 42, 0.38);
    z-index: 20;
}

.memo-modal {
    width: min(92vw, 340px);
    border: 1px solid var(--memo-border);
    border-radius: var(--memo-radius);
    background: var(--memo-bg);
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
    padding: 18px;
}

.memo-modal h2 {
    margin: 0 0 12px;
    font-size: 16px;
    color: var(--memo-text-strong);
}

.memo-modal p {
    margin: 0 0 14px;
    font-size: 13px;
    color: var(--memo-muted);
}

.memo-modal input,
.memo-modal textarea {
    width: 100%;
    margin-bottom: 14px;
    padding: 8px 10px;
    border: 1px solid var(--memo-border);
    border-radius: 6px;
    background: var(--memo-bg);
    color: var(--memo-text);
    font: inherit;
    font-size: 14px;
}

.memo-modal textarea {
    min-height: 84px;
    resize: vertical;
}

.memo-modal-error {
    margin: -6px 0 12px;
    color: var(--memo-danger);
    font-size: 12px;
}

.memo-modal-error[hidden] {
    display: none;
}

.memo-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.memo-modal-actions button {
    border: 1px solid var(--memo-border);
    border-radius: 6px;
    background: none;
    padding: 7px 14px;
    color: var(--memo-text);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

.memo-modal-actions .memo-modal-primary {
    background: var(--memo-accent);
    border-color: var(--memo-accent);
    color: #fff;
    font-weight: 700;
}

.memo-modal-actions .memo-modal-danger {
    background: var(--memo-danger);
    border-color: var(--memo-danger);
    color: #fff;
    font-weight: 700;
}

/* ---- 반응형: 좁은 화면에서는 사이드바 토글 ---- */

.memo-sidebar-toggle {
    display: none;
}

.memo-sidebar-backdrop {
    display: none;
}

/* 빈 상태 안내는 화면 폭에 맞는 문구만 노출. */
.memo-empty-mobile {
    display: none;
}

@media (max-width: 720px) {
    .memo-empty-desktop {
        display: none;
    }

    .memo-empty-mobile {
        display: block;
    }

    /* iOS는 16px 미만 입력 포커스 시 페이지를 자동 확대한다. */
    .memo-search,
    .memo-modal input {
        font-size: 16px;
    }

    .memo-shell.is-sidebar-open .memo-sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.35);
        z-index: 9;
    }

    .memo-sidebar-toggle {
        display: grid;
        place-items: center;
        position: fixed;
        top: 10px;
        left: 12px;
        width: 44px;
        height: 44px;
        border: 1px solid var(--memo-border);
        border-radius: 50%;
        background: var(--memo-bg-alt);
        color: var(--memo-text);
        font-size: 18px;
        cursor: pointer;
        box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
        z-index: 15;
    }

    .memo-shell {
        grid-template-columns: 1fr;
    }

    .memo-sidebar {
        display: none;
    }

    .memo-shell.is-sidebar-open .memo-sidebar {
        display: flex;
        position: fixed;
        inset: 0 25% 0 0;
        z-index: 10;
        box-shadow: 0 0 40px rgba(15, 23, 42, 0.18);
    }

    /* 좌상단 ☰ 버튼 자리를 비워 본문·헤더 글자가 가리지 않게 한다. */
    .memo-banner {
        padding-left: 64px;
    }

    /* 좌상단 ☰ 자리를 비운다. 툴바 버튼 4개는 좁은 폭에서 제목과 한 줄에 못 들어가므로
       제목이 한 줄을 독차지하고 버튼은 아랫줄로 내린다(사이드바 헤더와 같은 처리). */
    .memo-note-head {
        padding: 12px 14px 4px 64px;
    }

    .memo-note-titlebar {
        flex-wrap: wrap;
        row-gap: 6px;
    }

    .memo-note-titlebar .memo-title-input {
        flex-basis: 100%;
    }

    /* 좌상단 ☰ 자리를 비우면 헤더 폭이 좁아져 버튼이 서랍 밖으로 밀린다 — 줄바꿈 허용. */
    .memo-shell.is-sidebar-open .memo-sidebar-head {
        padding-left: 60px;
        flex-wrap: wrap;
        row-gap: 8px;
    }

    .memo-editor-host .cm-scroller {
        padding: 6px 14px 40vh;
    }
}

/* ---- 주석 모아보기 패널 (우측, 토글) ---- */

.memo-shell.is-annotation-open {
    grid-template-columns: 260px 1fr 300px;
}

.memo-annotation-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--memo-bg-alt);
    border-left: 1px solid var(--memo-border);
}

.memo-annotation-panel[hidden] {
    display: none;
}

.memo-annotation-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px 8px;
}

.memo-annotation-panel-head h2 {
    margin: 0;
    font-size: 14px;
    color: var(--memo-text-strong);
}

.memo-annotation-panel-head button {
    border: 0;
    border-radius: 6px;
    background: none;
    padding: 2px 8px;
    color: var(--memo-muted);
    font-size: 18px;
    line-height: 1.3;
    cursor: pointer;
}

.memo-annotation-panel-head button:hover,
.memo-annotation-panel-head button:focus-visible {
    background: var(--memo-bg-hover);
    color: var(--memo-text);
}

.memo-annotation-list {
    flex: 1;
    overflow-y: auto;
    padding: 2px 10px 20px;
    display: grid;
    gap: 8px;
    align-content: start;
}

.memo-annotation-item {
    border: 1px solid var(--memo-border);
    border-radius: var(--memo-radius);
    background: var(--memo-bg);
    padding: 8px 10px;
}

.memo-annotation-item-jump {
    display: block;
    width: 100%;
    border: 0;
    background: none;
    padding: 0;
    text-align: left;
    font: inherit;
    cursor: pointer;
}

.memo-annotation-item-phrase {
    display: inline-block;
    margin-bottom: 4px;
    padding: 0 3px;
    border-radius: 3px;
    background: rgba(125, 211, 252, 0.4);
    color: var(--memo-text-strong);
    font-size: 13px;
    font-weight: 600;
    word-break: break-word;
}

.memo-annotation-item-note {
    display: block;
    color: var(--memo-text);
    font-size: 12.5px;
    line-height: 1.5;
    word-break: break-word;
}

.memo-annotation-item-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 6px;
}

.memo-annotation-item-actions button {
    border: 1px solid var(--memo-border);
    border-radius: 6px;
    background: none;
    padding: 3px 9px;
    color: var(--memo-text);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
}

.memo-annotation-item-actions button:hover,
.memo-annotation-item-actions button:focus-visible {
    background: var(--memo-bg-hover);
    outline: none;
}

.memo-annotation-item-actions .memo-annotation-item-danger {
    color: var(--memo-danger);
}

.memo-annotation-empty {
    margin: 6px 14px;
    color: var(--memo-faint);
    font-size: 12.5px;
    line-height: 1.6;
}

/* 노트 헤더 토글 버튼의 개수 배지. */
.memo-annotation-count {
    display: inline-block;
    margin-left: 5px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--memo-accent-soft);
    color: var(--memo-accent);
    font-size: 11px;
    font-weight: 700;
    line-height: 1.6;
    vertical-align: 1px;
}

.memo-annotation-backdrop {
    display: none;
}

/* 좁은 화면: 패널은 우측에서 덮는 오버레이 + 백드롭(좌측 사이드바 패턴 준용). */
@media (max-width: 720px) {
    .memo-shell.is-annotation-open {
        grid-template-columns: 1fr;
    }

    .memo-annotation-panel {
        position: fixed;
        inset: 0 0 0 25%;
        z-index: 12;
        box-shadow: 0 0 40px rgba(15, 23, 42, 0.18);
    }

    .memo-shell.is-annotation-open .memo-annotation-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.35);
        z-index: 11;
    }
}
