/* Blocks — Minimal Modern (design.md 토큰 기준) */
:root {
  --bg: #FFFFFF;
  --bg-muted: #F9FAFB;
  --bg-subtle: #F4F4F5;
  --fg: #09090B;
  --fg-muted: #52525B;
  --fg-subtle: #71717A;
  --border: #E4E4E7;
  --border-strong: #D4D4D8;
  --primary: #18181B;
  --on-primary: #FFFFFF;
  --accent: #2563EB;
  --error: #DC2626;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --font-sans: 'Pretendard Variable', Pretendard, Inter, -apple-system, 'Apple SD Gothic Neo', sans-serif;
  --font-mono: 'JetBrains Mono', 'IBM Plex Mono', ui-monospace, Menlo, Consolas, monospace;
}
[data-theme="dark"] {
  --bg: #09090B;
  --bg-muted: #131316;
  --bg-subtle: #131316;
  --fg: #FAFAFA;
  --fg-muted: #D4D4D8;
  --fg-subtle: #A1A1AA;
  --border: #27272A;
  --border-strong: #27272A;
  --primary: #FAFAFA;
  --on-primary: #09090B;
  --accent: #60A5FA;
}
[data-theme="dark"] .btn-primary:hover { background: #E4E4E7; border-color: #E4E4E7; }

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--bg); color: var(--fg);
  font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#app { height: 100dvh; display: flex; flex-direction: column; }

/* Header */
.topbar {
  height: 60px; flex-shrink: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 0 24px;
  background: rgba(255,255,255,.8);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
[data-theme="dark"] .topbar { background: rgba(9,9,11,.8); }
.brand { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; white-space: nowrap; }
.save-state { font-size: 14px; color: var(--fg-muted); white-space: nowrap; }
.spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px;
  font-size: 14px; font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: transparent; color: var(--fg);
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--bg-subtle); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: #2A2A2E; border-color: #2A2A2E; }
#btnInstall[hidden] { display: none; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; flex-shrink: 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: transparent; color: var(--fg); cursor: pointer;
}
.icon-btn:hover { background: var(--bg-subtle); }

.layout { flex: 1; display: flex; min-height: 0; }

/* Sidebar + tree */
#sidebar {
  width: 300px; flex-shrink: 0;
  background: var(--bg-muted);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.side-tools { padding: 16px 16px 12px; }
.search-wrap { position: relative; }
.search-wrap svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--fg-subtle); pointer-events: none; }
.search-wrap input, .search-wrap #search { padding-left: 36px; }
#search, .text-input {
  width: 100%; height: 40px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 0 12px;
  font-size: 14px; font-family: inherit; color: var(--fg); outline: none;
}
#search::placeholder, .text-input::placeholder { color: var(--fg-subtle); }
#search:focus, .text-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(37,99,235,.2); }
.tree { list-style: none; padding: 0 12px 16px; overflow-y: auto; flex: 1; }
.tree ul { list-style: none; }
.tree-empty { padding: 24px 16px; text-align: center; font-size: 14px; color: var(--fg-muted); }
.tree-row {
  display: flex; align-items: center; gap: 2px;
  border-radius: var(--radius-md);
  padding: 2px 4px 2px calc(4px + var(--depth, 0) * 16px);
  min-height: 40px;
}
.tree-row:hover { background: var(--bg-subtle); }
.tree-row.active { background: var(--bg-subtle); }
.tree-row.active .tree-title { color: var(--accent); font-weight: 600; }
.tree-chev {
  width: 28px; height: 28px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; background: transparent; color: var(--fg-subtle);
  border-radius: 6px; cursor: pointer;
}
.tree-chev svg { transition: transform .15s; }
.tree-chev.open svg { transform: rotate(90deg); }
.tree-chev.leaf { visibility: hidden; }
.tree-title {
  flex: 1; min-width: 0; text-align: left;
  border: 0; background: transparent; color: var(--fg);
  font-size: 14px; font-weight: 500; padding: 6px 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer;
}
.tree-act {
  width: 28px; height: 28px; flex-shrink: 0;
  display: none; align-items: center; justify-content: center;
  border: 0; background: transparent; color: var(--fg-muted);
  border-radius: 6px; cursor: pointer;
}
.tree-row:hover .tree-act { display: inline-flex; }
.tree-act:hover { background: var(--bg); color: var(--fg); }
.tree-act.danger:hover { color: var(--error); }
.tree-rename { height: 36px; }
.side-foot { padding: 12px 16px; border-top: 1px solid var(--border); font-size: 13px; color: var(--fg-muted); }

/* Editor */
.editor-area { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.page-head { padding: 32px 0 8px; max-width: 760px; width: 100%; margin: 0 auto; padding-left: 24px; padding-right: 24px; }
#pageTitle {
  width: 100%; font-size: 32px; font-weight: 700; line-height: 40px; letter-spacing: -0.02em;
  border: 0; background: transparent; color: var(--fg); outline: none; font-family: inherit;
}
#pageTitle::placeholder { color: var(--fg-subtle); }
.meta { font-size: 12px; font-weight: 500; color: var(--fg-subtle); font-family: var(--font-sans); margin-top: 4px; }
#blocks {
  flex: 1; overflow-y: auto;
  max-width: 760px; width: 100%; margin: 0 auto;
  padding: 8px 24px 120px;
  counter-reset: blocknum;
}
.blocks-empty {
  display: block; width: 100%; text-align: left;
  border: 1px dashed var(--border-strong); border-radius: var(--radius-lg);
  background: transparent; color: var(--fg-subtle);
  font-size: 14px; padding: 20px; cursor: pointer; margin-top: 8px;
}
.blocks-empty:hover { border-color: var(--accent); color: var(--fg-muted); }

.block { display: flex; align-items: flex-start; border-radius: 6px; }
.block.drop-before { box-shadow: 0 -2px 0 var(--accent); }
.block.drop-after { box-shadow: 0 2px 0 var(--accent); }
.block.dragging { opacity: .5; }
.grip {
  width: 24px; min-height: 28px; flex-shrink: 0;
  display: inline-flex; align-items: flex-start; justify-content: center;
  padding-top: 7px; color: var(--fg-subtle);
  opacity: 0; cursor: grab; border-radius: 6px;
}
.block:hover .grip { opacity: 1; }
.grip:active { cursor: grabbing; }

.bedit {
  flex: 1; min-width: 0; outline: none; caret-color: var(--fg);
  font-size: 16px; line-height: 1.7;
  padding: 3px 2px;
  margin-left: calc(var(--indent, 0) * 24px);
  word-break: break-word;
}
.bedit:empty::before { content: attr(data-placeholder); color: var(--fg-subtle); pointer-events: none; }
.b-h1 { font-size: 32px; font-weight: 700; line-height: 40px; letter-spacing: -0.02em; margin-top: 16px; }
.b-h2 { font-size: 24px; font-weight: 600; line-height: 32px; letter-spacing: -0.01em; margin-top: 16px; }
.b-h3 { font-size: 20px; font-weight: 600; line-height: 28px; margin-top: 12px; }
.b-quote { border-left: 3px solid var(--border-strong); padding-left: 16px; color: var(--fg-muted); }
.b-bulleted { position: relative; padding-left: 24px; }
.b-bulleted::before { content: "•"; position: absolute; left: 8px; }
.b-numbered { position: relative; padding-left: 24px; counter-increment: blocknum; }
.b-numbered::before { content: counter(blocknum) "."; position: absolute; left: 2px; font-variant-numeric: tabular-nums; }
.b-code {
  font-family: var(--font-mono); font-size: 14px;
  background: var(--bg-muted); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 12px 16px; margin: 4px 0;
  white-space: pre-wrap;
}
.b-divider { padding: 8px 2px; }
.b-divider hr { border: 0; border-top: 1px solid var(--border); }
.todo-box { width: 18px; height: 18px; margin: 7px 8px 0 2px; flex-shrink: 0; accent-color: var(--primary); cursor: pointer; }
.block.done .bedit { color: var(--fg-subtle); text-decoration: line-through; }

/* Slash menu — dropdown 규격 */
.slash-menu {
  position: fixed; z-index: 100;
  width: 288px; max-height: 320px; overflow-y: auto;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 6px;
  box-shadow: 0 12px 32px rgba(0,0,0,.08);
}
.slash-item { padding: 8px 12px; border-radius: var(--radius-md); cursor: pointer; }
.slash-item.active, .slash-item:hover { background: var(--bg-subtle); }
.slash-name { font-size: 14px; font-weight: 600; }
.slash-desc { font-size: 12px; font-weight: 500; color: var(--fg-subtle); }
.slash-empty { padding: 12px; font-size: 14px; color: var(--fg-muted); text-align: center; }

/* Dialog */
#syncDialog {
  border: 1px solid var(--border); border-radius: var(--radius-xl);
  background: var(--bg); color: var(--fg);
  padding: 28px; width: min(92vw, 480px);
  margin: auto; max-height: calc(100dvh - 48px);
  box-shadow: 0 12px 32px rgba(0,0,0,.08);
}
#syncDialog::backdrop { background: rgba(0,0,0,.4); }
#syncDialog h3 { font-size: 20px; font-weight: 600; line-height: 28px; margin-bottom: 8px; }
#syncDialog .dlg-desc { font-size: 14px; color: var(--fg-muted); margin-bottom: 4px; }
#syncDialog .dlg-url { font-size: 12px; font-weight: 500; color: var(--fg-subtle); margin-bottom: 8px; }
#syncDialog .dlg-url code { font-family: var(--font-mono); font-size: 12px; word-break: break-all; }
#syncDialog .field { margin-bottom: 16px; }
#syncDialog .field > label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
#syncDialog .row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
#syncDialog .row.end { justify-content: flex-end; margin-top: 20px; }
#syncDialog .check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 16px 0 0; cursor: pointer; }
#syncDialog .check input { width: 16px; height: 16px; accent-color: var(--primary); }
.dlg-status { font-size: 14px; font-weight: 600; margin: 16px 0 0; }
.dlg-status.subtle { color: var(--fg-muted); font-weight: 400; }

.only-mobile { display: none; }
#scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 29; }

/* 블록 추가 버튼 + 멀티선택 */
.addbtn {
  width: 24px; height: 28px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; background: transparent; color: var(--fg-subtle);
  opacity: 0; cursor: pointer; border-radius: 6px; padding: 0;
}
.block:hover .addbtn { opacity: 1; }
.addbtn:hover { background: var(--bg-subtle); color: var(--fg); }
.block.selected { background: var(--bg-subtle); border-radius: 6px; }
.block.selected .bedit { background: transparent; }

/* 서식 버블 메뉴 */
.bubble {
  position: fixed; z-index: 120; display: none;
  align-items: center; gap: 2px;
  background: var(--primary); color: var(--on-primary);
  border-radius: 12px; padding: 6px;
  box-shadow: 0 12px 32px rgba(0,0,0,.18);
}
.bubble.show { display: flex; }
.bubble button {
  border: 0; background: transparent; color: inherit;
  min-width: 36px; height: 36px; padding: 0 8px;
  border-radius: 8px; cursor: pointer;
  font-size: 14px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
}
.bubble button:hover { background: rgba(255,255,255,.15); }
[data-theme="dark"] .bubble button:hover { background: rgba(0,0,0,.08); }
.bubble button code { font-family: var(--font-mono); font-size: 12px; }

/* 임베드 */
.b-embed { width: 100%; }
.b-embed img { max-width: 100%; border-radius: var(--radius-md); border: 1px solid var(--border); display: block; }
.b-embed iframe { width: 100%; aspect-ratio: 16/9; border: 1px solid var(--border); border-radius: var(--radius-lg); }
.embed-inputrow { display: flex; gap: 8px; flex-wrap: wrap; }
.embed-inputrow .text-input { flex: 1; min-width: 200px; }
.embed-card {
  display: block; border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px 20px; text-decoration: none; color: var(--fg);
}
.embed-card:hover { border-color: var(--border-strong); }
.embed-card-title { font-size: 14px; font-weight: 600; }
.embed-card-url { font-size: 12px; font-weight: 500; color: var(--fg-subtle); font-family: var(--font-mono); margin-top: 2px; word-break: break-all; }
.embed-card-go { font-size: 14px; color: var(--accent); margin-top: 8px; }

/* 데이터베이스 */
.b-database { width: 100%; }
.dbview { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; background: var(--bg); }
.db-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.db-title { border: 0; background: transparent; color: var(--fg); font-size: 16px; font-weight: 600; cursor: pointer; padding: 4px 0; font-family: inherit; text-align: left; }
.db-title-input { max-width: 280px; }
.db-views { display: flex; background: var(--bg-subtle); border: 1px solid var(--border); border-radius: 9999px; padding: 2px; }
.db-viewbtn { border: 0; background: transparent; color: var(--fg-muted); height: 32px; padding: 0 14px; border-radius: 9999px; font-size: 13px; font-weight: 500; cursor: pointer; }
.db-viewbtn.active { background: var(--bg); color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.db-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.db-table th { text-align: left; padding: 8px 12px; font-size: 12px; font-weight: 600; color: var(--fg-muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
.db-table td { padding: 6px 12px; border-bottom: 1px solid var(--border); }
.db-ptype { font-weight: 500; color: var(--fg-subtle); margin-left: 6px; font-size: 11px; }
.db-cell { width: 100%; min-width: 80px; height: 36px; border: 1px solid transparent; border-radius: 8px; padding: 0 8px; font-size: 14px; font-family: inherit; color: var(--fg); background: transparent; }
.db-cell:hover { border-color: var(--border); }
.db-cell:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(37,99,235,.2); outline: none; background: var(--bg); }
.todo-box.cell { margin: 0; }
.db-x { border: 0; background: transparent; color: var(--fg-subtle); cursor: pointer; font-size: 16px; padding: 4px 8px; border-radius: 6px; }
.db-x:hover { color: var(--error); background: var(--bg-subtle); }
.db-addbtn { border: 1px dashed var(--border-strong); background: transparent; color: var(--fg-muted); border-radius: 8px; padding: 8px 12px; font-size: 13px; font-weight: 500; cursor: pointer; margin-top: 8px; }
.db-addbtn:hover { color: var(--fg); border-color: var(--fg-subtle); }
.db-propform { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.db-propform .text-input { flex: 1; min-width: 140px; }
.db-boardempty { font-size: 14px; color: var(--fg-muted); padding: 16px 4px; }
.db-board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 4px; }
.db-col { min-width: 240px; flex: 1; background: var(--bg-muted); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 12px; }
.db-col.drop { border-color: var(--accent); }
.db-colhead { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.db-coldot { width: 10px; height: 10px; border-radius: 50%; background: var(--border-strong); flex-shrink: 0; }
.db-colname { font-size: 14px; font-weight: 600; flex: 1; }
.db-colcount { font-size: 12px; font-weight: 500; color: var(--fg-subtle); font-family: var(--font-mono); }
.db-card { position: relative; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px; margin-bottom: 8px; cursor: grab; }
.db-card:hover { border-color: var(--border-strong); }
.db-cardtitle { font-size: 14px; font-weight: 600; padding-right: 24px; }
.db-cardsub { font-size: 12px; font-weight: 500; color: var(--fg-subtle); margin-top: 4px; }
.db-x.card { position: absolute; top: 4px; right: 4px; display: none; }
.db-card:hover .db-x.card { display: block; }
.db-addbtn.col { width: 100%; border-style: dashed; }

/* 트리 DnD */
.tree-grip {
  width: 20px; height: 28px; flex-shrink: 0;
  display: none; align-items: center; justify-content: center;
  color: var(--fg-subtle); cursor: grab; border-radius: 6px;
}
.tree-row:hover .tree-grip { display: inline-flex; }
.tree-row.drop-before { box-shadow: 0 -2px 0 var(--accent); }
.tree-row.drop-after { box-shadow: 0 2px 0 var(--accent); }
.tree-row.drop-inside { background: var(--bg-subtle); outline: 2px solid var(--accent); outline-offset: -2px; }

@media (max-width: 768px) {
  .topbar { padding: 0 20px; }
  .only-mobile { display: inline-flex; align-items: center; justify-content: center; }
  .brand { display: none; }
  #sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 30;
    transform: translateX(-105%); transition: transform .2s ease;
    width: min(84vw, 320px);
  }
  #sidebar.open { transform: none; box-shadow: 0 12px 32px rgba(0,0,0,.08); }
  #pageTitle { font-size: 28px; line-height: 34px; }
  .page-head, #blocks { padding-left: 20px; padding-right: 20px; }
  .grip { opacity: 1; }
  .addbtn { opacity: 1; }
  #syncDialog { padding: 24px 20px; }
}
