/* Derrick Notion — dark mode only. EXACT ADOC palette. */
:root{
  --bg:#0d1117; --card-bg:#161b22; --text:#e6edf3; --text-muted:#8b949e;
  --border:#30363d; --green:#3fb950; --yellow:#d29922; --red:#f85149;
  --blue:#58a6ff; --gray:#484f58; --orange:#f0883e;
  --sidebar-w:264px;
  --mono:ui-monospace,SFMono-Regular,Menlo,monospace;
}

*{box-sizing:border-box;}
[hidden]{display:none !important;}
html,body{height:100%;}
body{
  margin:0; background:var(--bg); color:var(--text);
  font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif;
  font-size:15px; line-height:1.6;
  -webkit-font-smoothing:antialiased;
}
::selection{background:rgba(88,166,255,.30);}

#app{display:flex; height:100vh; overflow:hidden;}

/* ---------------- Sidebar ---------------- */
#sidebar{
  width:var(--sidebar-w); flex:0 0 var(--sidebar-w);
  background:#0b0f14; border-right:1px solid var(--border);
  display:flex; flex-direction:column; min-height:0;
  transition:margin-left .18s ease;
}
#app.collapsed #sidebar{ margin-left:calc(-1 * var(--sidebar-w)); }
.sidebar-head{
  display:flex; align-items:center; justify-content:space-between;
  padding:14px 14px 10px; gap:8px;
}
.brand{font-weight:600; font-size:14.5px; letter-spacing:.2px; color:var(--text); display:flex; align-items:center; gap:8px;}
.brand-mark{color:var(--blue); font-size:12px;}
.tree{flex:1 1 auto; overflow-y:auto; padding:4px 8px 8px;}
.new-page{
  margin:6px 10px; padding:8px 10px; border:1px solid var(--border);
  background:var(--card-bg); color:var(--text-muted); border-radius:8px;
  cursor:pointer; font-size:13.5px; text-align:left; transition:all .12s;
}
.new-page:hover{color:var(--text); border-color:var(--gray); background:#1b222b;}
.sidebar-foot{
  display:flex; align-items:center; gap:8px; padding:10px 16px;
  border-top:1px solid var(--border); font-size:12px; color:var(--text-muted);
}
.dot{width:8px;height:8px;border-radius:50%;background:var(--gray);box-shadow:0 0 0 0 rgba(63,185,80,.4);}
.dot.live{background:var(--green); animation:pulse 2.4s infinite;}
.dot.down{background:var(--red);}
@keyframes pulse{0%{box-shadow:0 0 0 0 rgba(63,185,80,.4);}70%{box-shadow:0 0 0 6px rgba(63,185,80,0);}100%{box-shadow:0 0 0 0 rgba(63,185,80,0);}}

/* ---- tree rows ---- */
.row{display:flex; align-items:center; gap:2px; border-radius:6px; padding:1px 4px; user-select:none;}
.row:hover{background:#161d27;}
.row.active{background:#1f6feb33;}
.row.drop-into{background:#1f6feb55; outline:1px dashed var(--blue);}
.caret{
  width:18px;height:18px;flex:0 0 18px;display:flex;align-items:center;justify-content:center;
  color:var(--text-muted); cursor:pointer; border-radius:4px; font-size:10px; transition:transform .12s;
}
.caret:hover{background:#222a35; color:var(--text);}
.caret.open{transform:rotate(90deg);}
.caret.leaf{visibility:hidden;}
.row .ico{width:18px;flex:0 0 18px;text-align:center;font-size:14px;}
.row .label{
  flex:1 1 auto; padding:4px 4px; font-size:13.5px; color:var(--text);
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis; cursor:pointer;
}
.row.active .label{font-weight:600;}
.row .add{
  width:20px;flex:0 0 20px;opacity:0;color:var(--text-muted);cursor:pointer;border-radius:4px;
  text-align:center;font-size:15px;line-height:18px;
}
.row:hover .add{opacity:1;}
.row .add:hover{background:#222a35;color:var(--text);}
.children{margin-left:14px; border-left:1px solid #20262e; padding-left:2px;}

/* ---------------- Main ---------------- */
#main{flex:1 1 auto; overflow-y:auto; position:relative;}
.expand-btn{
  position:fixed; top:12px; left:12px; z-index:20;
  width:30px;height:30px;border:1px solid var(--border);background:var(--card-bg);
  color:var(--text-muted);border-radius:8px;cursor:pointer;
}
.expand-btn:hover{color:var(--text);}
.icon-btn{
  background:none;border:none;color:var(--text-muted);cursor:pointer;font-size:14px;
  width:26px;height:26px;border-radius:6px;
}
.icon-btn:hover{background:#161d27;color:var(--text);}

.breadcrumb{
  display:flex; align-items:center; gap:6px; flex-wrap:wrap;
  padding:14px 56px 0; font-size:12.5px; color:var(--text-muted); min-height:30px;
}
.breadcrumb .crumb{cursor:pointer; padding:2px 4px; border-radius:4px; white-space:nowrap;}
.breadcrumb .crumb:hover{background:#161d27; color:var(--text);}
.breadcrumb .sep{opacity:.5;}

#page-view{max-width:820px; margin:0; padding:8px 56px 40vh;}
.title-row{display:flex; align-items:flex-start; gap:12px; margin:18px 0 6px;}
.page-icon{
  font-size:40px; line-height:1; background:none; border:none; cursor:pointer;
  width:52px; min-width:52px; height:52px; border-radius:10px; color:var(--text-muted);
}
.page-icon:hover{background:#161d27;}
.page-icon:empty::before{content:'＋'; font-size:22px; opacity:.4;}
.page-title{
  flex:1 1 auto; margin:0; font-size:38px; line-height:1.15; font-weight:700;
  outline:none; border:none; color:var(--text); padding:4px 0;
}
.page-title:empty::before{content:attr(data-ph); color:var(--gray);}

/* ---------------- Editor / blocks ---------------- */
.editor{margin-top:10px;}
.block{position:relative;}
.block-row{display:flex; align-items:flex-start; gap:4px; padding:1px 0; border-radius:4px;}
.block-row:hover{background:#10151c;}
.grip{
  flex:0 0 18px; width:18px; margin-top:5px; color:#3b434d; cursor:grab; opacity:0;
  text-align:center; font-size:12px; user-select:none; border-radius:4px; line-height:1.2;
}
.block-row:hover .grip{opacity:1;}
.grip:hover{color:var(--text-muted); background:#1b222b;}
.block.dragging{opacity:.4;}
.block.drop-after > .block-row{box-shadow:inset 0 -2px 0 var(--blue);}
.block.drop-into > .block-row{box-shadow:inset 0 0 0 1px var(--blue);}

.prefix{flex:0 0 auto; color:var(--text-muted); margin-top:0; user-select:none; min-width:18px; text-align:right;}
.editable{
  flex:1 1 auto; outline:none; min-height:1.6em; padding:1px 2px; white-space:pre-wrap; word-break:break-word;
}
.editable:empty::before{content:attr(data-ph); color:var(--gray); pointer-events:none;}

/* type styles */
.block[data-type="heading_1"] .editable{font-size:1.7em; font-weight:700; line-height:1.3;}
.block[data-type="heading_2"] .editable{font-size:1.4em; font-weight:700; line-height:1.3;}
.block[data-type="heading_3"] .editable{font-size:1.17em; font-weight:600;}
.block[data-type="heading_1"] .block-row,
.block[data-type="heading_2"] .block-row,
.block[data-type="heading_3"] .block-row{margin-top:6px;}

.block[data-type="bulleted_list_item"] .prefix{margin-top:0;}
.block[data-type="quote"] .block-row{border-left:3px solid var(--gray); padding-left:10px; margin-left:2px;}
.block[data-type="quote"] .editable{color:var(--text); font-style:italic;}

.callout{
  display:flex; gap:10px; width:100%; background:var(--card-bg);
  border:1px solid var(--border); border-radius:8px; padding:10px 12px;
}
.callout .cico{font-size:16px; line-height:1.5;}

.todo-check{
  appearance:none; width:16px; height:16px; margin-top:5px; border:1.5px solid var(--gray);
  border-radius:4px; cursor:pointer; flex:0 0 16px; background:var(--bg); position:relative;
}
.todo-check:checked{background:var(--blue); border-color:var(--blue);}
.todo-check:checked::after{content:'✓'; color:#fff; font-size:11px; position:absolute; left:2px; top:-2px;}
.block.checked .editable{color:var(--text-muted); text-decoration:line-through;}

.toggle-caret{flex:0 0 18px;width:18px;margin-top:3px;color:var(--text-muted);cursor:pointer;text-align:center;font-size:10px;transition:transform .12s;}
.toggle-caret.open{transform:rotate(90deg);}
.block.collapsed > .children{display:none;}

pre.code{
  width:100%; background:#0b0f14; border:1px solid var(--border); border-radius:8px;
  padding:12px 14px; margin:2px 0; overflow:auto; position:relative;
}
pre.code .editable{font-family:var(--mono); font-size:13px; color:#cdd9e5; white-space:pre;}
pre.code .lang{position:absolute; top:6px; right:10px; font-size:11px; color:var(--text-muted); font-family:var(--mono);}

hr.divider{border:none; border-top:1px solid var(--border); margin:10px 0;}

.page-link{
  display:flex; align-items:center; gap:8px; width:100%; padding:4px 6px; border-radius:6px;
  cursor:pointer; color:var(--text); text-decoration:none; border:1px solid transparent;
}
.page-link:hover{background:#161d27; border-color:var(--border);}
.page-link .pico{font-size:16px;}
.page-link .ptitle{font-weight:500; border-bottom:1px solid var(--gray);}

.img-block img{max-width:100%; border-radius:8px; border:1px solid var(--border);}
.img-block .img-url{
  width:100%; background:var(--card-bg); border:1px dashed var(--border); color:var(--text-muted);
  border-radius:8px; padding:10px; font-size:13px;
}
.img-block .cap{font-size:12.5px; color:var(--text-muted); margin-top:4px;}

/* ---------------- Empty state ---------------- */
.empty-state{
  height:100%; display:flex; flex-direction:column; align-items:center; justify-content:center;
  text-align:center; color:var(--text-muted); gap:6px; padding:40px;
}
.empty-emoji{font-size:46px;}
.empty-state h1{color:var(--text); font-size:22px; margin:8px 0 2px;}
.empty-state p{margin:0 0 16px; max-width:380px;}
.primary{
  background:var(--blue); color:#06101f; border:none; padding:10px 18px; border-radius:8px;
  font-weight:600; cursor:pointer; font-size:14px;
}
.primary:hover{filter:brightness(1.08);}

/* ---------------- Slash + icon menus ---------------- */
.slash-menu,.icon-menu{
  position:absolute; z-index:50; background:var(--card-bg); border:1px solid var(--border);
  border-radius:10px; box-shadow:0 12px 34px rgba(0,0,0,.5); padding:6px; min-width:248px;
  max-height:320px; overflow-y:auto;
}
.slash-item{
  display:flex; align-items:center; gap:10px; padding:7px 9px; border-radius:7px; cursor:pointer;
}
.slash-item .si-ico{
  width:30px;height:30px;flex:0 0 30px;display:flex;align-items:center;justify-content:center;
  background:var(--bg); border:1px solid var(--border); border-radius:6px; font-size:15px;
}
.slash-item .si-name{font-size:13.5px; color:var(--text);}
.slash-item .si-desc{font-size:11.5px; color:var(--text-muted);}
.slash-item.sel,.slash-item:hover{background:#1f6feb22;}
.slash-section{font-size:10.5px; text-transform:uppercase; letter-spacing:.6px; color:var(--text-muted); padding:6px 9px 2px;}
.icon-menu{display:grid; grid-template-columns:repeat(8,1fr); gap:2px; min-width:auto;}
.icon-menu button{background:none;border:none;font-size:18px;cursor:pointer;padding:5px;border-radius:6px;}
.icon-menu button:hover{background:#1f6feb22;}

/* ---------------- Inline rich text: text color + background (Notion-style) ---------------- */
.tc-gray{color:#b9bdc4;} .tc-brown{color:#c08552;} .tc-orange{color:#f0883e;}
.tc-yellow{color:#d9a32a;} .tc-green{color:#4dab63;} .tc-blue{color:#58a6ff;}
.tc-purple{color:#a371f7;} .tc-pink{color:#d2649a;} .tc-red{color:#f85149;}
.bg-gray{background:rgba(139,148,158,.22);} .bg-brown{background:rgba(160,119,99,.28);}
.bg-orange{background:rgba(240,136,62,.22);} .bg-yellow{background:rgba(210,153,34,.25);}
.bg-green{background:rgba(63,185,80,.22);} .bg-blue{background:rgba(88,166,255,.22);}
.bg-purple{background:rgba(163,113,247,.24);} .bg-pink{background:rgba(210,100,154,.24);}
.bg-red{background:rgba(248,81,73,.22);}
/* inline background gets a small pill; block-level bg on .editable fills the line */
span[class*="bg-"]{padding:0 2px;border-radius:3px;}
.editable[class*="bg-"]{padding:1px 5px;border-radius:5px;}
/* legacy highlights — still rendered for old content */
.hl-yellow{background:rgba(210,153,34,.25);padding:0 2px;border-radius:3px;}
.hl-green{background:rgba(63,185,80,.22);padding:0 2px;border-radius:3px;}
.hl-blue{background:rgba(88,166,255,.22);padding:0 2px;border-radius:3px;}
.hl-red{background:rgba(248,81,73,.22);padding:0 2px;border-radius:3px;}
.hl-orange{background:rgba(240,136,62,.22);padding:0 2px;border-radius:3px;}
.hl-gray{background:rgba(139,148,158,.22);padding:0 2px;border-radius:3px;}

/* block context menu + color submenu + selection popover */
.ctx-menu{position:absolute; z-index:90; background:var(--card-bg); border:1px solid var(--border);
  border-radius:10px; box-shadow:0 12px 34px rgba(0,0,0,.5); padding:6px; min-width:184px;}
.ctx-item{display:flex; align-items:center; justify-content:space-between; gap:12px;
  padding:7px 9px; border-radius:7px; cursor:pointer; font-size:13.5px; color:var(--text);}
.ctx-item:hover,.ctx-item.open{background:#1f6feb22;}
.ctx-item .chev{color:var(--text-muted); font-size:11px;}
.color-menu{position:absolute; z-index:95; background:var(--card-bg); border:1px solid var(--border);
  border-radius:10px; box-shadow:0 12px 34px rgba(0,0,0,.5); padding:6px; min-width:210px; max-height:70vh; overflow-y:auto;}
.color-sec{font-size:10.5px; text-transform:uppercase; letter-spacing:.5px; color:var(--text-muted); padding:7px 8px 3px;}
.color-item{display:flex; align-items:center; gap:10px; padding:6px 8px; border-radius:7px; cursor:pointer; font-size:13.5px; color:var(--text);}
.color-item:hover{background:#1f6feb22;}
.color-chip{width:22px; height:22px; flex:0 0 22px; border:1px solid var(--border); border-radius:5px;
  display:flex; align-items:center; justify-content:center; font-weight:700; font-size:13px; background:var(--bg);}
.selection-popover{position:absolute; z-index:85; background:var(--card-bg); border:1px solid var(--border);
  border-radius:8px; box-shadow:0 8px 24px rgba(0,0,0,.5); padding:3px; display:flex; gap:2px;}
.selection-popover button{background:none; border:none; color:var(--text); cursor:pointer; font-size:13px;
  padding:5px 10px; border-radius:6px; display:flex; align-items:center;}
.selection-popover button:hover{background:#1f6feb22;}

/* ---------------- In-page search (jump-to-heading) ---------------- */
.page-search{
  position:sticky; top:0; z-index:20;
  display:flex; align-items:center; gap:8px;
  margin:0 0 16px; padding:8px 12px;
  background:var(--card-bg); border:1px solid var(--border); border-radius:10px;
}
.page-search .ps-ico{ color:var(--text-muted); font-size:13px; line-height:1; }
.page-search .ps-input{
  flex:1 1 auto; background:transparent; border:none; outline:none;
  color:var(--text); font-size:14.5px; font-family:inherit;
}
.page-search .ps-input::placeholder{ color:var(--text-muted); }
.page-search .ps-count{ color:var(--text-muted); font-size:12.5px; white-space:nowrap; font-variant-numeric:tabular-nums; }
.page-search .ps-clear{
  border:none; background:transparent; color:var(--text-muted); cursor:pointer;
  font-size:13px; padding:2px 7px; border-radius:6px; line-height:1;
}
.page-search .ps-clear:hover{ color:var(--text); background:#1b222b; }
.block.ps-hit{
  border-radius:6px;
  box-shadow:0 0 0 2px var(--blue), 0 0 0 6px rgba(88,166,255,.18);
  background:rgba(31,111,235,.10);
  transition:box-shadow .15s ease, background .15s ease;
}

/* ===================== MOBILE LAYOUT (phones / narrow) ===================== */
@media (max-width: 760px){
  #app{ flex-direction:column; height:100dvh; }

  /* Sidebar: full-width panel on top, capped + scrollable. Collapse hides it. */
  #sidebar{
    width:100%; flex:0 0 auto; max-height:40vh;
    border-right:none; border-bottom:1px solid var(--border);
  }
  #app.collapsed #sidebar{ margin-left:0; display:none; }

  /* Main + page get the full width */
  #main{ flex:1 1 auto; width:100%; }
  #page-view{ max-width:100%; padding:8px 16px 30vh; }
  .breadcrumb{ padding:12px 16px 0; }
  .page-search{ margin:0 0 12px; }

  /* Kill the cramped wrapping */
  .editable{ word-break:normal; overflow-wrap:anywhere; }
  pre.code{ overflow-x:auto; }

  /* Sizing tuned for small screens */
  .page-title{ font-size:28px; }
  .page-icon{ font-size:32px; width:42px; min-width:42px; height:42px; }
  .title-row{ gap:8px; }

  /* No hover/drag affordances on touch — reclaim the space */
  .grip{ display:none; }
  .block-row{ gap:6px; }
  .row .add{ opacity:1; }

  /* Hamburger sits clear of content */
  .expand-btn{ top:10px; left:10px; }
}

/* ---- sidebar row delete (trash) ---- */
.row .del{
  width:20px;flex:0 0 20px;opacity:0;color:var(--text-muted);cursor:pointer;border-radius:4px;
  text-align:center;font-size:12.5px;line-height:18px;
}
.row:hover .del{opacity:.85;}
.row .del:hover{background:rgba(248,81,73,.18);color:var(--red);opacity:1;}
