/* Plangrida 웹앱 스타일 — 앱 레이아웃 그대로 (좌:목록 / 우:캔버스) */

* { box-sizing: border-box; }
:root {
    --sidebar-w: 280px;
    --bg: #f7f8fb;
    --panel: #ffffff;
    --border: #e3e6ec;
    --border-soft: #eef0f5;
    --text: #1d2230;
    --muted: #7a8499;
    --muted-soft: #aab1c1;
    --accent: #2f6dff;
    --accent-dark: #1f4dcc;
    --accent-soft: #eaf0ff;
    --danger: #d0363a;
    --warn: #ea8800;
    --postit: #fff5a8;
    --postit-border: #f0df79;
    --postit-shadow: rgba(20, 26, 38, .12);
}
html, body {
    margin: 0; padding: 0; height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Noto Sans KR", Helvetica, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

/* ── Auth 공용 폼 ───────────────────────────────────── */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
    width: 100%; max-width: 420px;
    background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
    padding: 28px; box-shadow: 0 4px 24px rgba(0,0,0,.04);
}
.auth-card .brand {
    display: flex; justify-content: center; margin: 0 0 18px;
}
.auth-card .brand img { width: 220px; max-width: 100%; height: auto; display: block; }
.auth-card h1 { margin: 0 0 4px; font-size: 24px; text-align: center; }
.auth-card .subtitle { margin: 0 0 24px; color: var(--muted); font-size: 14px; text-align: center; }
.field { display: flex; flex-direction: column; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input {
    padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
    font-size: 14px; background: #fff;
}
.field input:focus { outline: 2px solid rgba(47,109,255,.25); border-color: var(--accent); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 14px; border: 1px solid var(--border); border-radius: 8px;
    background: #fff; cursor: pointer; font-size: 13px; color: var(--text);
    font-family: inherit;
    transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.btn:hover { background: #f3f5fa; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.block { width: 100%; }
.btn.danger { color: var(--danger); border-color: var(--border); }
.btn.danger:hover { background: #fef1f1; border-color: var(--danger); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.divider { display: flex; align-items: center; gap: 10px; margin: 18px 0; color: var(--muted); font-size: 12px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.alert { padding: 10px 12px; border-radius: 8px; background: #fef1f1; color: var(--danger); font-size: 13px; margin-bottom: 12px; }
.muted { color: var(--muted); }
.link { color: var(--accent); text-decoration: none; }
.link:hover { text-decoration: underline; }

/* ── Splash ─────────────────────────────────────────── */
.splash { min-height: 100vh; display: grid; place-items: center; }
.splash-box { text-align: center; }
.splash-box h1 { font-size: 32px; margin: 0 0 4px; }
.spinner {
    width: 24px; height: 24px; margin: 16px auto 0;
    border: 3px solid var(--border); border-top-color: var(--accent);
    border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════════════════════════════════════════════════════
   App 레이아웃
   ═══════════════════════════════════════════════════════ */
.app {
    display: grid; grid-template-columns: var(--sidebar-w) 1fr;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────── */
.sidebar {
    background: var(--panel);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    min-height: 0;
}
.side-head {
    padding: 14px 16px 12px;
    border-bottom: 1px solid var(--border-soft);
}
.side-head .brand { display: flex; align-items: center; gap: 10px; }
.side-head .brand .mark { width: 28px; height: 28px; flex: 0 0 auto; display: block; }
.side-head .brand .name { display: flex; flex-direction: column; line-height: 1.1; }
.side-head .brand .name strong { font-size: 15px; font-weight: 800; letter-spacing: .02em; color: var(--text); }
.side-head .brand .name strong em { font-style: normal; color: var(--accent); }
.side-head .brand .name .tag { font-size: 10px; color: var(--muted); margin-top: 2px; letter-spacing: .03em; }
.side-head h2 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.side-head .sync-line { font-size: 11px; color: var(--muted); margin-top: 8px; }

.sidebar .section-title {
    font-size: 11px; color: var(--muted-soft);
    text-transform: uppercase; letter-spacing: .06em; font-weight: 600;
    padding: 14px 16px 6px;
}

.side-foot {
    margin-top: auto; padding: 12px 12px 14px;
    border-top: 1px solid var(--border-soft);
    font-size: 12px;
}
.side-foot .email { color: var(--muted); margin-bottom: 8px; padding: 0 4px; overflow: hidden; text-overflow: ellipsis; }

/* + 템플릿 추가 버튼 */
.add-tpl-btn {
    margin: 12px 12px 2px;
    padding: 10px 12px;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    background: var(--accent-soft); border: 1px solid transparent;
    color: var(--accent); font-weight: 500; font-size: 13px;
    border-radius: 8px; cursor: pointer;
    font-family: inherit;
    transition: background .12s ease, border-color .12s ease;
}
.add-tpl-btn:hover { background: #dbe6ff; border-color: rgba(47,109,255,.25); }
.add-tpl-btn .plus { font-size: 15px; line-height: 1; font-weight: 600; }

/* 트리 */
.doc-tree {
    flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
    padding: 0 0 12px;
}
.doc-tree .tree-empty {
    padding: 18px 16px; font-size: 12px; color: var(--muted);
    white-space: pre-line; line-height: 1.6;
}

.tree-group { margin: 0; }
.tree-group-head {
    display: flex; align-items: center; gap: 6px;
    padding: 7px 14px 7px 12px;
    cursor: pointer; user-select: none;
    color: var(--text);
}
.tree-group-head:hover { background: #f3f5fa; }
.tree-group-head .chev {
    display: inline-block; width: 14px; height: 14px; flex: 0 0 14px;
    position: relative;
}
.tree-group-head .chev::before {
    content: ""; position: absolute; left: 3px; top: 3px;
    width: 6px; height: 6px;
    border-right: 1.5px solid var(--muted);
    border-bottom: 1.5px solid var(--muted);
    transform: rotate(45deg);             /* 펼침: ▾ */
    transition: transform .15s ease;
}
.tree-group.collapsed .tree-group-head .chev::before {
    transform: rotate(-45deg);            /* 접힘: ▸ */
    left: 5px; top: 1px;
}
.tree-group-head .name { flex: 1; font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-group-head .count {
    font-size: 11px; color: var(--muted);
    background: var(--border-soft); border-radius: 10px; padding: 1px 7px;
    font-weight: 500; line-height: 1.5;
}

.tree-group-list { margin: 0; padding: 0; list-style: none; }
.tree-group.collapsed .tree-group-list { display: none; }

.tree-doc {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 14px 6px 30px;
    cursor: pointer;
    border-left: 3px solid transparent;
    font-size: 13px; color: var(--text);
    line-height: 1.4;
}
.tree-doc:hover { background: #f3f5fa; }
.tree-doc.active { background: var(--accent-soft); border-left-color: var(--accent); color: var(--accent-dark); font-weight: 500; }
.tree-doc .title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree-doc .dirty { font-size: 10px; color: var(--warn); }

/* ═══════════════════════════════════════════════════════
   Detail (우측)
   ═══════════════════════════════════════════════════════ */
.detail {
    display: flex; flex-direction: column;
    min-height: 0; min-width: 0;
    background: var(--bg);
    overflow: hidden;
}

/* 상단 바: 문서 정보 + 툴바 */
.detail-bar {
    flex: 0 0 auto;
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 14px 20px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}
.detail-header { min-width: 0; flex: 1; }
.dh-kind {
    font-size: 11px; color: var(--muted);
    font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
    margin-bottom: 2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dh-title-row {
    display: flex; align-items: center; gap: 4px;
    min-width: 0; max-width: 100%;
}
.dh-title {
    flex: 0 1 auto;
    min-width: 0;
    font-size: 17px; font-weight: 600; line-height: 1.25;
    color: var(--text);
    padding: 2px 6px; margin-left: -6px;
    border-radius: 5px;
    outline: none;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dh-title[contenteditable="true"] {
    background: #fff;
    box-shadow: 0 0 0 2px rgba(47,109,255,.35);
    overflow: visible;
    cursor: text;
}
.dh-title[data-empty="1"] { color: var(--muted); font-weight: 500; }

.dh-edit {
    flex: 0 0 auto;
    width: 28px; height: 28px;
    padding: 0;
    border: none; background: transparent;
    color: var(--muted); border-radius: 6px;
    cursor: pointer;
    display: grid; place-items: center;
    transition: background .12s ease, color .12s ease;
}
.dh-edit:hover { background: var(--accent-soft); color: var(--accent); }
.dh-edit:active { background: #dbe6ff; }
.dh-title[data-empty="1"] ~ .dh-edit { display: none; }

.toolbar {
    flex: 0 0 auto;
    display: flex; gap: 4px;
    background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 3px;
}
.toolbar .btn { padding: 6px 10px; font-size: 12px; border: none; }
.toolbar .btn:hover { background: #fff; }

/* 캔버스 호스트 */
.canvas-host {
    flex: 1; min-height: 0;
    position: relative; overflow: hidden;
    display: grid; place-items: center;
    cursor: grab;
    padding: 24px;
}
.canvas-host.panning { cursor: grabbing; }

.canvas {
    position: relative;
    background: #fff;
    border: 1px solid var(--border);
    box-shadow: 0 8px 32px rgba(15, 23, 42, .08);
    transform-origin: center center;
    transition: transform .06s linear;
}

/* 섹션 */
.canvas .section {
    position: absolute;
    border: 1px solid rgba(122,132,153,.3);
    padding: 8px 8px 6px;
    overflow: hidden;
    background: transparent;
    display: flex; flex-direction: column;
    transition: background .12s ease, border-color .12s ease;
}
.canvas .section:hover { background: rgba(47,109,255,.025); }
.canvas .section.drag-over {
    background: rgba(47,109,255,.08);
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent);
}
.canvas .sec-title {
    font-size: 10px; color: var(--muted); font-weight: 700;
    text-transform: uppercase; letter-spacing: .04em;
}
.canvas .sec-sub { font-size: 9px; color: var(--muted-soft); margin-bottom: 6px; }

/* 노트(포스트잇) 영역 */
.canvas .notes {
    flex: 1; min-height: 0;
    display: flex; flex-wrap: wrap; gap: 4px;
    align-content: flex-start;
    overflow: hidden;
    padding: 2px 0;
}
.canvas .note {
    background: var(--postit);
    border: 1px solid var(--postit-border);
    border-radius: 3px;
    padding: 5px 7px;
    font-size: 10px; line-height: 1.35;
    color: #2a2419;
    max-width: 100%;
    min-width: 40px;
    cursor: grab;
    user-select: none;
    white-space: pre-wrap; word-break: break-word;
    box-shadow: 0 1px 2px var(--postit-shadow), 0 0 0 1px rgba(255,255,255,.3) inset;
    transition: transform .1s ease, box-shadow .1s ease;
}
.canvas .note:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(20, 26, 38, .18), 0 0 0 1px rgba(255,255,255,.3) inset;
}
.canvas .note:active { cursor: grabbing; }
.canvas .note.dragging { opacity: .4; }

/* 드로잉 카드 (Apple Pencil — 읽기 전용) */
.canvas .note.note-drawing {
    background: #fff;
    border: 1px solid var(--border);
    padding: 2px;
    cursor: default;
}
.canvas .note.note-drawing:hover { transform: none; }
.canvas .note.note-drawing img {
    display: block;
    max-width: 120px; max-height: 80px;
    object-fit: contain;
}
.canvas .note.note-pending {
    background: var(--border-soft);
    border: 1px dashed var(--border);
    color: var(--muted);
    font-size: 9px;
    cursor: default;
}
.canvas .note.note-pending:hover { transform: none; }

.canvas .add-note {
    align-self: flex-start;
    margin-top: 4px;
    background: transparent;
    border: 1px dashed rgba(122,132,153,.4);
    color: var(--muted);
    font-size: 10px; font-family: inherit;
    padding: 2px 8px; border-radius: 3px;
    cursor: pointer;
    transition: border-color .12s ease, color .12s ease, background .12s ease;
}
.canvas .add-note:hover {
    border-color: var(--accent); color: var(--accent);
    background: rgba(47,109,255,.04);
    border-style: solid;
}

/* 빈 상태 */
.empty {
    position: absolute; inset: 0;
    display: grid; place-items: center;
    color: var(--muted); text-align: center; padding: 32px;
    pointer-events: none;
}
.empty p { margin: 8px 0 0; font-size: 14px; line-height: 1.6; }
.empty-icon { font-size: 40px; opacity: .6; }

/* ═══════════════════════════════════════════════════════
   Modal (공용)
   ═══════════════════════════════════════════════════════ */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(20, 26, 38, .48);
    display: grid; place-items: center; z-index: 100;
    padding: 20px;
    animation: fadeIn .12s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
    width: min(520px, 100%);
    max-height: calc(100vh - 40px);
    background: #fff; border-radius: 14px;
    padding: 22px 22px 18px;
    box-shadow: 0 20px 60px rgba(0,0,0,.22);
    display: flex; flex-direction: column;
    overflow: hidden;
}
.modal h3 { margin: 0 0 2px; font-size: 18px; font-weight: 700; }
.modal .sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.modal textarea {
    width: 100%; min-height: 140px; padding: 10px 12px;
    border: 1px solid var(--border); border-radius: 8px;
    font-family: inherit; font-size: 14px; resize: vertical;
    color: var(--text); background: #fff;
}
.modal textarea:focus { outline: 2px solid rgba(47,109,255,.25); border-color: var(--accent); }
.modal .actions {
    display: flex; justify-content: flex-end; gap: 8px;
    margin-top: 14px;
    flex-wrap: wrap;
}

/* 템플릿 피커 (카드 그리드) */
.modal.picker { width: min(640px, 100%); }
.modal.picker .template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    overflow-y: auto;
    padding: 2px;
}
.template-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    text-align: left;
    cursor: pointer;
    font-family: inherit; color: var(--text);
    display: flex; flex-direction: column; gap: 6px;
    transition: border-color .12s ease, transform .12s ease, box-shadow .12s ease;
}
.template-card:hover {
    border-color: var(--accent);
    box-shadow: 0 6px 18px rgba(47,109,255,.12);
    transform: translateY(-1px);
}
.template-card .tc-preview {
    position: relative;
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border-soft);
    border-radius: 5px;
    margin-bottom: 4px;
    overflow: hidden;
}
.template-card .tc-cell {
    position: absolute;
    border: 1px solid rgba(47,109,255,.3);
    background: rgba(47,109,255,.06);
}
.template-card .tc-name { font-size: 14px; font-weight: 600; }
.template-card .tc-en   { font-size: 11px; color: var(--muted); margin-top: -2px; }
.template-card .tc-desc {
    font-size: 12px; color: var(--muted); line-height: 1.5;
    margin-top: 4px;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ═══════════════════════════════════════════════════════
   반응형
   ═══════════════════════════════════════════════════════ */
@media (max-width: 760px) {
    .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
    .sidebar { border-right: none; border-bottom: 1px solid var(--border); max-height: 48vh; }
    .detail-bar { padding: 10px 14px; gap: 10px; }
    .dh-title { font-size: 15px; }
}
