/* ── RESET ── */
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
html,body{height:100%;overflow:hidden}
body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;font-size:14px;line-height:1.5;color:#222;background:#fff}

/* Focus visible for keyboard nav */
:focus-visible{outline:2px solid #1a73e8;outline-offset:2px;border-radius:3px}

/* Cycle 0007A: respect prefers-reduced-motion — near-zero rather than
   transition:none, so anything checking transitionend (there isn't
   currently, but this keeps it safe if that changes) still fires. */
@media (prefers-reduced-motion: reduce){
  *,*::before,*::after{transition-duration:.01ms!important;animation-duration:.01ms!important;animation-iteration-count:1!important}
}

/* ── ROOT LAYOUT ── */
#app{
  position:fixed;top:0;left:0;right:0;bottom:0;
  display:flex;flex-direction:row;overflow:hidden
}

/* ════════════════════════════
   SIDEBAR  (220px fixed)
════════════════════════════ */
#sidebar{
  width:220px;min-width:220px;flex-shrink:0;
  height:100%;display:flex;flex-direction:column;overflow-y:auto;overflow-x:hidden;
  background:#f4f4f4;border-right:1px solid #d8d8d8
}
.sb-logo{
  padding:16px 16px 12px;font-size:.88rem;font-weight:700;color:#333;
  letter-spacing:.3px;user-select:none;flex-shrink:0
}
.sb-search-wrap{padding:0 12px 6px;flex-shrink:0}
.sb-search{
  display:flex;align-items:center;gap:6px;width:100%;
  padding:8px 10px;background:#e4e4e4;border:none;border-radius:6px;
  font-size:.82rem;color:#555;cursor:pointer;text-align:left;min-height:36px
}
.sb-search:hover{background:#d8d8d8}
.sb-new-wrap{padding:0 12px 10px;flex-shrink:0}
.sb-new{
  display:flex;align-items:center;justify-content:center;gap:6px;width:100%;
  padding:10px;background:#1a73e8;border:none;border-radius:6px;
  font-size:.84rem;font-weight:600;color:#fff;cursor:pointer;min-height:40px
}
.sb-new:hover{background:#1558b0}
.sb-new:disabled{opacity:.6;cursor:not-allowed}
.sb-nav{padding:0 6px;flex-shrink:0}
.sb-nav-item{
  display:flex;align-items:center;gap:9px;width:100%;
  padding:9px 10px;background:none;border:none;border-radius:6px;
  font-size:.84rem;color:#444;cursor:pointer;text-align:left;min-height:44px
}
.sb-nav-item:hover{background:#e4e4e4}
.sb-nav-item.active{background:#d3e2fd;color:#1a73e8;font-weight:600}
.sb-trash{margin-bottom:8px}
.sb-icon{width:16px;height:16px;flex-shrink:0}
.sb-divider{height:1px;background:#ddd;margin:6px 12px;flex-shrink:0}
.sb-spacer{flex:1}
.sb-section-btn{
  display:flex;align-items:center;justify-content:space-between;width:100%;
  padding:7px 16px;background:none;border:none;font-size:.75rem;
  font-weight:700;color:#666;cursor:pointer;text-transform:uppercase;letter-spacing:.6px;min-height:32px
}
.sb-section-btn:hover{color:#333}
.sb-caret{width:13px;height:13px;transition:transform .15s;color:currentColor}
.sb-caret.open{transform:rotate(0deg)}
.sb-caret.closed{transform:rotate(-90deg)}
.sb-section-body{padding:0 6px}
.sb-nb-item,.sb-tag-item{
  display:flex;align-items:center;gap:8px;width:100%;
  padding:6px 10px;background:none;border:none;border-radius:5px;
  font-size:.82rem;color:#444;cursor:pointer;text-align:left;min-height:34px;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis
}
.sb-nb-item:hover,.sb-tag-item:hover{background:#e4e4e4}
.sb-nb-item.active,.sb-tag-item.active{background:#d3e2fd;color:#1a73e8}
.sb-add-btn{
  width:100%;padding:5px 16px;background:none;border:none;
  font-size:.78rem;color:#6b7280;cursor:pointer;text-align:left
}
.sb-add-btn:hover{color:#1a73e8}

/* ════════════════════════════
   CONTENT AREA
════════════════════════════ */
#contentArea{
  flex:1;min-width:0;height:100%;
  display:flex;flex-direction:row;position:relative;overflow:hidden
}

/* ════════════════════════════
   NOTES PANEL  (310px default)
════════════════════════════ */
#notesPanel{
  width:310px;min-width:180px;max-width:480px;flex-shrink:0;
  height:100%;display:flex;flex-direction:column;
  overflow:hidden;background:#fff;border-right:1px solid #e5e5e5
}
.np-header{flex-shrink:0;border-bottom:1px solid #e5e5e5}
.np-titlerow{display:flex;align-items:baseline;gap:6px;padding:14px 16px 4px}
.np-title{font-size:.95rem;font-weight:700;color:#222}
.np-count{font-size:.75rem;color:#6b7280}
.np-tabs{display:flex;align-items:center;gap:2px;padding:0 12px 6px}
.np-tabs-spacer{flex:1}
.np-tab{
  padding:5px 10px;background:none;border:none;border-bottom:2px solid transparent;
  font-size:.8rem;color:#666;cursor:pointer;min-height:34px
}
.np-tab.active{border-bottom-color:#1a73e8;color:#1a73e8;font-weight:600}
.np-tab[aria-disabled="true"]{color:#ccc;cursor:default}
.np-tab:hover:not(.active):not([aria-disabled="true"]){color:#333}
.np-icon-btn{
  padding:6px 7px;background:none;border:none;border-radius:4px;
  cursor:pointer;color:#666;display:flex;align-items:center;min-height:32px
}
.np-icon-btn:hover{background:#eee;color:#333}
.filter-bar{
  display:flex;align-items:center;gap:6px;padding:6px 12px;
  background:#fef3c7;border-bottom:1px solid #f0d080;font-size:.78rem;color:#666;flex-shrink:0
}
.filter-bar button{margin-left:auto;background:none;border:none;cursor:pointer;color:#6b7280;padding:2px 6px}

/* TRW-807: bounded notes pager */
.notes-pager{
  display:flex;align-items:center;justify-content:space-between;gap:8px;
  padding:8px 12px;border-top:1px solid #eee;font-size:.78rem;color:#666;flex-shrink:0
}
.notes-pager button{background:#f5f5f5;border:1px solid #ddd;border-radius:4px;cursor:pointer;padding:4px 10px;color:#333}
.notes-pager button:disabled{opacity:.4;cursor:default}

/* note cards */
#notesList{flex:1;overflow-y:auto}
.note-card{padding:11px 16px;border-bottom:1px solid #f0f0f0;cursor:pointer;position:relative;border-left:3px solid transparent}
.note-card:hover{background:#f5f5f5}
.note-card.active{background:#dce8fc;border-left-color:#1a73e8}
.nc-title{font-size:.84rem;font-weight:600;color:#222;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;margin-bottom:2px}
.nc-sub{font-size:.76rem;color:#6b7280;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;display:flex;gap:8px}
.nc-date{font-size:.72rem;color:#6b7280;margin-top:2px}
.nc-tags{display:flex;gap:3px;flex-wrap:wrap;margin-top:4px}
.nc-tag{background:#e8f0fe;color:#1a73e8;font-size:.69rem;padding:2px 7px;border-radius:10px}
.empty-list{padding:32px 16px;text-align:center;color:#6b7280;font-size:.82rem}

/* ════════════════════════════
   DRAG HANDLE
════════════════════════════ */
#dragHandle{width:4px;height:100%;flex-shrink:0;background:transparent;cursor:col-resize}
#dragHandle:hover,#dragHandle:focus{background:#c8c8c8;outline:none}

/* ════════════════════════════
   EDITOR PANEL
════════════════════════════ */
#editorPanel{flex:1;min-width:0;height:100%;display:flex;flex-direction:column;overflow:hidden;background:#fff;position:relative}

/* empty state */
.empty-state{
  position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;
  justify-content:center;background:#fff;gap:12px;z-index:5
}
.es-title{font-size:1rem;font-weight:500;color:#6b7280}
.es-sub{font-size:.85rem;color:#6b7280}

/* breadcrumb */
.breadcrumb{
  display:flex;align-items:center;gap:6px;
  padding:10px 28px 6px;font-size:.79rem;color:#6b7280;flex-shrink:0;
  border-bottom:1px solid #f5f5f5
}
.bc-nb{background:none;border:none;cursor:pointer;color:#1a73e8;font-size:.79rem;padding:0}
.bc-nb:hover{text-decoration:underline}
.bc-date{margin-left:auto;color:#6b7280}

/* toolbar */
.ed-toolbar{
  display:flex;align-items:center;flex-shrink:0;
  padding:6px 14px;border-bottom:1px solid #e5e5e5;gap:2px;flex-wrap:wrap;background:#fafafa
}
.tb-left{display:flex;align-items:center;gap:2px;flex:1;flex-wrap:wrap}
.tb-right{display:flex;align-items:center;gap:2px;flex-shrink:0}
.tb-btn{
  padding:5px 8px;background:none;border:none;border-radius:4px;
  font-size:.8rem;color:#444;cursor:pointer;white-space:nowrap;min-height:30px
}
.tb-btn:hover{background:#eee}
.tb-btn:disabled{opacity:.45;cursor:not-allowed}
.tb-icon{padding:5px 7px;font-size:.82rem}
.tb-caret{font-size:.6rem;opacity:.6}
.tb-sep{width:1px;height:18px;background:#ddd;margin:0 3px;flex-shrink:0}
.tb-select{
  border:1px solid #e0e0e0;background:#fff;border-radius:4px;
  font-size:.78rem;padding:4px 5px;color:#444;max-width:105px;cursor:pointer;min-height:28px
}
.tb-size{
  width:48px;border:1px solid #e0e0e0;border-radius:4px;
  font-size:.78rem;padding:3px 5px;color:#444;background:#fff;text-align:center;min-height:28px
}
.tb-color-wrap{position:relative;display:inline-flex;align-items:center}
#colorPick{position:absolute;opacity:0;width:0;height:0;pointer-events:none}
.color-swatch{display:inline-block;width:11px;height:3px;border-radius:2px;background:#222;margin-right:2px;vertical-align:middle}

/* find bar */
.find-bar{
  display:flex;align-items:center;gap:8px;padding:6px 14px;
  border-bottom:1px solid #e5e5e5;background:#fffde7;flex-shrink:0
}
.find-bar input{flex:1;border:1px solid #ddd;border-radius:4px;padding:4px 8px;font-size:.82rem;outline:none}
.find-bar input:focus{border-color:#1a73e8}
.find-count{font-size:.76rem;color:#6b7280;white-space:nowrap}
.find-nav-btn{padding:3px 8px;background:#eee;border:none;border-radius:4px;cursor:pointer;font-size:.8rem}
.find-nav-btn:hover{background:#ddd}
.find-close-btn{padding:3px 8px;background:none;border:none;cursor:pointer;color:#6b7280;font-size:.85rem;margin-left:4px}
.find-close-btn:hover{color:#333}

/* editor content */
.ed-title-wrap{padding:10px 28px 2px;flex-shrink:0}
.ed-title{
  width:100%;border:none;outline:none;font-size:1.3rem;font-weight:700;
  color:#111;padding:4px 0;background:transparent;caret-color:#1a73e8
}
.ed-title::placeholder{color:#ccc}
.ed-title:disabled{background:transparent;cursor:default}
.ed-body-wrap{flex:1;overflow-y:auto;padding:4px 28px 20px}
.ed-body{
  min-height:200px;outline:none;font-size:.88rem;line-height:1.75;
  color:#333;white-space:pre-wrap;word-break:break-word
}
.ed-body:empty::before{content:attr(data-placeholder);color:#ccc;pointer-events:none}
.ed-body h1{font-size:1.5rem;font-weight:700;margin:8px 0}
.ed-body h2{font-size:1.15rem;font-weight:600;margin:6px 0}
.ed-body pre{
  background:#f6f8fa;padding:10px 14px;border-radius:5px;
  font-family:'Courier New',monospace;font-size:.82rem;overflow-x:auto;margin:8px 0;
  white-space:pre-wrap
}
.ed-body a{color:#1a73e8}
.ed-body mark{background:#fffb8f;border-radius:2px;color:inherit}

/* footer */
.ed-footer{
  display:flex;align-items:center;flex-shrink:0;
  padding:6px 16px;border-top:1px solid #ececec;gap:6px;background:#fff;min-height:42px
}
.footer-btn{
  display:flex;align-items:center;gap:5px;padding:5px 10px;
  background:none;border:1px dashed #ccc;border-radius:4px;font-size:.76rem;
  color:#6b7280;cursor:pointer;flex-shrink:0;white-space:nowrap
}
.footer-btn:hover{border-color:#999;color:#555}
.tag-chips{display:flex;flex-wrap:wrap;gap:4px;flex:1}
.tag-chip{
  display:flex;align-items:center;gap:3px;background:#f0f4ff;
  color:#3b5bdb;padding:3px 9px;border-radius:10px;font-size:.73rem
}
.tag-chip button{
  background:none;border:none;cursor:pointer;color:#8fa6e8;
  font-size:.7rem;padding:0 0 0 2px;line-height:1
}
.tag-chip button:hover{color:#e03}
.save-status{font-size:.74rem;color:#6b7280;margin-left:auto;min-width:65px;text-align:right;white-space:nowrap}

/* ════════════════════════════
   DROPDOWNS
════════════════════════════ */
.dd-wrap{position:relative;display:inline-flex}
.dropdown{
  display:none;position:absolute;top:calc(100% + 4px);left:0;
  min-width:160px;background:#fff;border:1px solid #e0e0e0;
  border-radius:8px;box-shadow:0 4px 20px rgba(0,0,0,.13);
  z-index:9999;padding:4px 0;font-size:.82rem
}
.dd-right{left:auto}
.dropdown.open{display:block}
.dd-head{padding:6px 12px;font-size:.7rem;font-weight:700;color:#6b7280;text-transform:uppercase;letter-spacing:.6px}
.dd-sep{height:1px;background:#f0f0f0;margin:3px 0}
.dd-item{
  display:flex;align-items:center;width:100%;min-height:44px;box-sizing:border-box;
  padding:8px 14px;cursor:pointer;color:#333;
  white-space:nowrap;background:none;border:none;text-align:left;font-size:.82rem
}
.dd-item:hover{background:#f0f0f0}
.dd-red{color:#dc2626}
.dd-red:hover{background:#fff0f0}
.dd-h1{font-size:1rem;font-weight:700}
.dd-h2{font-weight:600}

/* ════════════════════════════
   FULL VIEWS
   position:absolute relative to #contentArea (position:relative)
   → sidebar always stays visible
════════════════════════════ */
.full-view{
  position:absolute;top:0;left:0;right:0;bottom:0;
  overflow-y:auto;background:#fff;padding:32px 40px;z-index:10
}
.fv-head{display:flex;align-items:center;gap:16px;margin-bottom:24px}
.fv-head h2{font-size:1.3rem;font-weight:700}
.fv-hint{font-size:.85rem;color:#666;margin-bottom:20px;max-width:600px;line-height:1.6}
.fv-hint code{background:#f0f0f0;padding:1px 5px;border-radius:3px;font-size:.8rem}
.fv-sub{font-size:.9rem;font-weight:600;color:#555;margin-bottom:12px}

/* notebooks grid */
.nb-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(180px,1fr));gap:14px}
.nb-card{padding:18px 20px;background:#f8f9ff;border:1px solid #dde4f8;border-radius:8px;cursor:pointer}
.nb-card:hover{background:#ecf0ff;border-color:#b3c2f5}
.nb-card-title{font-size:.88rem;font-weight:600;margin-bottom:4px}
.nb-card-count{font-size:.74rem;color:#6b7280}

/* tags grid */
.tag-grid{display:flex;flex-wrap:wrap;gap:8px}
.tag-card{
  display:flex;align-items:center;gap:6px;padding:7px 16px;
  background:#f0f4ff;border:1px solid #c8d6f8;border-radius:20px;
  cursor:pointer;font-size:.82rem;color:#3b5bdb
}
.tag-card:hover{background:#dce8ff}

/* trash */
#trashList{display:flex;flex-direction:column;gap:2px}
.trash-item{display:flex;align-items:center;gap:12px;padding:10px 14px;border-radius:7px}
.trash-item:hover{background:#f5f5f5}
.trash-item-title{flex:1;color:#333;font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.trash-date{font-size:.72rem;color:#6b7280;flex-shrink:0}
.restore-btn,.del-btn{padding:4px 12px;border:none;border-radius:4px;font-size:.73rem;cursor:pointer;flex-shrink:0}
.restore-btn{background:#e8f0fe;color:#1a73e8}
.del-btn{background:#fff0f0;color:#dc2626}

/* home */
.home-stats{display:flex;gap:16px;margin-bottom:28px;flex-wrap:wrap}
.stat-card{flex:1;min-width:110px;padding:16px 20px;background:#f8f9ff;border:1px solid #dde4f8;border-radius:8px;text-align:center}
.stat-num{font-size:1.5rem;font-weight:700;color:#1a73e8}
.stat-lbl{font-size:.75rem;color:#6b7280;margin-top:2px}
.notes-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(200px,1fr));gap:12px}
.home-card{padding:14px 16px;background:#fff;border:1px solid #e8e8e8;border-radius:8px;cursor:pointer}
.home-card:hover{border-color:#b3c2f5;background:#f8f9ff}
.hc-title{font-size:.84rem;font-weight:600;margin-bottom:4px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.hc-preview{font-size:.76rem;color:#6b7280;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}

/* buttons */
.btn-primary{
  padding:8px 18px;background:#1a73e8;color:#fff;border:none;border-radius:6px;
  font-size:.84rem;font-weight:600;cursor:pointer;min-height:36px
}
.btn-primary:hover{background:#1558b0}
.btn-danger{
  padding:8px 18px;background:#dc2626;color:#fff;border:none;border-radius:6px;
  font-size:.84rem;font-weight:600;cursor:pointer;min-height:36px
}
.btn-danger:hover{background:#b91c1c}
.btn-secondary{
  padding:8px 18px;background:#f0f0f0;color:#444;border:none;border-radius:6px;
  font-size:.84rem;cursor:pointer;min-height:36px
}
.btn-secondary:hover{background:#e0e0e0}

/* ════════════════════════════
   OVERLAYS / MODALS
════════════════════════════ */
.overlay{
  position:fixed;inset:0;background:rgba(0,0,0,.4);
  display:flex;align-items:center;justify-content:center;z-index:200
}
.overlay[hidden]{display:none!important}
.search-box{
  width:560px;max-width:95vw;background:#fff;
  border-radius:10px;overflow:hidden;box-shadow:0 8px 36px rgba(0,0,0,.18)
}
.sb-row{display:flex;align-items:center;gap:10px;padding:14px 18px;border-bottom:1px solid #eee}
.sb-row input{flex:1;border:none;outline:none;font-size:.95rem;color:#222;background:transparent}
.icon-x{background:none;border:none;cursor:pointer;color:#6b7280;font-size:.9rem;padding:4px 8px}
.icon-x:hover{color:#333}
.sr-results{max-height:380px;overflow-y:auto}
.sr-item{padding:10px 18px;cursor:pointer;border-bottom:1px solid #f5f5f5}
.sr-item:hover{background:#f5f5f5}
.sr-title{font-size:.84rem;font-weight:600;color:#222}
.sr-snippet{font-size:.76rem;color:#6b7280}
.modal{
  background:#fff;padding:28px;border-radius:10px;
  min-width:340px;max-width:95vw;box-shadow:0 8px 36px rgba(0,0,0,.18)
}
.modal h3{margin-bottom:14px;font-size:1rem}
.modal-btns{display:flex;gap:8px;margin-top:18px}
.modal input[type=file]{margin:12px 0;display:block;width:100%;font-size:.84rem}
.file-error{color:#dc2626;font-size:.8rem;margin-top:6px}

/* info modal */
#infoContent p{margin-bottom:8px;font-size:.84rem}
#infoContent strong{color:#444}

/* ════════════════════════════
   SCROLLBAR
════════════════════════════ */
::-webkit-scrollbar{width:6px;height:6px}
::-webkit-scrollbar-track{background:transparent}
::-webkit-scrollbar-thumb{background:#ccc;border-radius:3px}
::-webkit-scrollbar-thumb:hover{background:#aaa}

/* ════════════════════════════
   MOBILE TOP BAR (hidden on desktop)
════════════════════════════ */
.mobile-top-bar{
  display:none;align-items:center;gap:10px;
  height:calc(44px + env(safe-area-inset-top));flex-shrink:0;
  padding:env(safe-area-inset-top) 12px 0 max(12px,env(safe-area-inset-left));
  background:#f4f4f4;border-bottom:1px solid #d8d8d8;z-index:100
}
.hamburger-btn{
  display:flex;align-items:center;justify-content:center;
  width:44px;height:44px;background:none;border:none;border-radius:6px;
  cursor:pointer;color:#444;flex-shrink:0
}
.hamburger-btn:hover{background:#e4e4e4}
.mobile-app-title{font-size:.9rem;font-weight:700;color:#333;flex:1}
.mobile-back-btn{
  min-height:44px;padding:6px 14px;background:none;border:1px solid #ccc;border-radius:6px;
  font-size:.8rem;color:#1a73e8;cursor:pointer;flex-shrink:0
}
.mobile-back-btn:hover{background:#e8f0fe}
.sidebar-overlay{
  display:none;position:fixed;inset:0;background:rgba(0,0,0,.4);z-index:140
}
.sidebar-overlay.active{display:block}

/* ════════════════════════════
   RESPONSIVE — 1024 × 768
   Sidebar collapses to icon rail
════════════════════════════ */
@media (max-width:1100px){
  #sidebar{width:52px;min-width:52px}
  .sb-logo,.sb-search-wrap,.sb-new-wrap,.sb-section-btn,.sb-section-body,.sb-add-btn,.sb-nav-item span{display:none}
  .sb-nav-item{justify-content:center;padding:10px 0;min-height:44px}
  .sb-trash{margin-bottom:6px}
  .sb-icon{width:18px;height:18px}
}

/* ════════════════════════════
   RESPONSIVE — 390 × 844 (mobile)
   Single-column, sidebar is a drawer overlay
════════════════════════════ */
@media (max-width:680px){
  #app{flex-direction:column}
  .mobile-top-bar{display:flex}

  /* Sidebar becomes a fixed left-drawer on mobile */
  #sidebar{
    position:fixed!important;top:0;left:-220px;height:100%;
    width:220px!important;min-width:220px!important;
    z-index:150;transition:left .2s ease;
    box-shadow:2px 0 12px rgba(0,0,0,.2);
    /* reset icon-rail overrides */
    overflow-y:auto;overflow-x:hidden;
    padding-top:env(safe-area-inset-top);
    padding-left:env(safe-area-inset-left);
    padding-bottom:env(safe-area-inset-bottom)
  }
  #sidebar.mobile-sidebar-open{left:0}
  /* restore all sidebar child elements hidden by 1100px rule */
  #sidebar .sb-logo,#sidebar .sb-search-wrap,#sidebar .sb-new-wrap,
  #sidebar .sb-section-btn,#sidebar .sb-section-body,
  #sidebar .sb-add-btn,#sidebar .sb-nav-item span{display:flex}
  #sidebar .sb-logo{display:block}
  #sidebar .sb-nav-item{justify-content:flex-start;padding:9px 10px}
  #sidebar .sb-nav-item span{display:inline}
  #sidebar .sb-add-btn{display:block}
  #sidebar .sb-section-btn{display:flex}
  #sidebar .sb-section-body{display:block}
  /* .sb-tag-add-child is opacity:0 until row :hover, which never fires on a
     touchscreen — without this it's unreachable on mobile, not just small.
     Still short of the 44px target (the tag-tree row has no room for that
     without its own redesign) — a real, flagged gap, not silently accepted. */
  #sidebar .sb-tag-add-child{opacity:1;width:28px;height:28px;min-width:28px}

  #contentArea{flex:1;min-height:0;flex-direction:column}
  #notesPanel{width:100%!important;max-width:100%;border:none;height:100%;flex-shrink:0}
  #dragHandle{display:none!important}
  #editorPanel{
    position:fixed!important;inset:0;top:calc(44px + env(safe-area-inset-top));z-index:50;
    padding-bottom:env(safe-area-inset-bottom);
    padding-left:env(safe-area-inset-left);
    padding-right:env(safe-area-inset-right);
    box-sizing:border-box;
    transform:translateX(100%);transition:transform .2s ease
  }
  #editorPanel.mobile-open{transform:translateX(0)}
  .ed-toolbar{flex-wrap:wrap}
  .full-view{padding:20px 16px}
}

/* ════════════════════════════
   CODE EXECUTION TOOLBAR
════════════════════════════ */
#codeToolbar{
  position:fixed;background:#1e1e2e;border:1px solid #3a3a5c;
  border-radius:8px;box-shadow:0 4px 20px rgba(0,0,0,.35);
  padding:6px 10px;display:flex;align-items:center;gap:8px;
  z-index:9997;font-size:.75rem;color:#cdd6f4;
  min-width:220px
}
#codeToolbar.hidden{display:none}
.ct-lang-badge{
  background:#313244;color:#89dceb;border-radius:4px;
  padding:2px 8px;font-size:.7rem;font-family:monospace;white-space:nowrap;
  border:none;cursor:pointer;-webkit-appearance:none;appearance:none
}
.ct-lang-badge:focus{outline:1px solid #89dceb}
#ctRunBtn{
  display:flex;align-items:center;gap:5px;
  padding:5px 12px;background:#a6e3a1;color:#1e1e2e;border:none;border-radius:5px;
  font-size:.78rem;font-weight:700;cursor:pointer;white-space:nowrap
}
#ctRunBtn:hover{background:#94e2d5}
#ctRunBtn:disabled{opacity:.5;cursor:not-allowed}
.ct-sep{width:1px;height:16px;background:#3a3a5c}
#ctCloseBtn{
  background:none;border:none;color:#6c7086;cursor:pointer;font-size:.8rem;padding:2px 4px;border-radius:3px
}
#ctCloseBtn:hover{color:#cdd6f4;background:#313244}
#ctCopyBtn{
  background:none;border:none;color:#6c7086;cursor:pointer;font-size:.72rem;
  padding:3px 7px;border-radius:4px;border:1px solid #3a3a5c;white-space:nowrap
}
#ctCopyBtn:hover{color:#cdd6f4;background:#313244}

/* code output panel (appended after pre) */
.code-output{
  font-family:'Courier New',monospace;font-size:.78rem;line-height:1.5;
  background:#11111b;color:#cdd6f4;border-radius:0 0 6px 6px;
  border:1px solid #313244;border-top:none;
  padding:10px 14px;max-height:260px;overflow-y:auto;
  white-space:pre-wrap;word-break:break-all;margin-bottom:6px;
  position:relative
}
.code-output.co-error{border-color:#f38ba8;background:#1a0a0e}
.co-header{
  display:flex;align-items:center;gap:8px;margin-bottom:6px;
  font-size:.7rem;padding-bottom:6px;border-bottom:1px solid #313244
}
.co-exit-ok{color:#a6e3a1}
.co-exit-err{color:#f38ba8}
.co-duration{color:#6c7086;margin-left:auto}
.co-stderr{color:#fab387}
.co-close{
  background:none;border:none;color:#6c7086;cursor:pointer;
  font-size:.75rem;position:absolute;top:6px;right:8px;padding:2px 5px
}
.co-close:hover{color:#cdd6f4}

/* selected pre highlight */
pre.pre-selected{outline:2px solid #89b4fa;outline-offset:2px}

/* ════════════════════════════
   UTILITIES
════════════════════════════ */
[hidden]{display:none!important}

/* ════════════════════════════
   TAG TREE (hierarchical)
════════════════════════════ */
.sb-tag-tree-item{
  display:flex;align-items:center;width:100%;
  padding:5px 10px 5px 10px;background:none;border:none;border-radius:5px;
  font-size:.82rem;color:#444;cursor:pointer;text-align:left;min-height:32px;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis;gap:3px;
  position:relative
}
.sb-tag-tree-item:hover{background:#e4e4e4}
.sb-tag-tree-item.active{background:#d3e2fd;color:#1a73e8}
.sb-tag-tree-row{display:flex;align-items:center;width:100%}
.sb-tag-toggle-btn{
  width:18px;height:18px;min-width:18px;background:none;border:none;
  cursor:pointer;color:#6b7280;font-size:.65rem;padding:0;flex-shrink:0;
  display:flex;align-items:center;justify-content:center;border-radius:3px
}
.sb-tag-toggle-btn:hover{background:#ddd;color:#333}
.sb-tag-indent{padding-left:16px}
.sb-tag-indent-2{padding-left:32px}
.sb-tag-add-child{
  opacity:0;width:16px;height:16px;min-width:16px;background:none;border:none;
  cursor:pointer;color:#6b7280;font-size:.65rem;padding:0;margin-left:2px;flex-shrink:0;
  border-radius:3px;display:flex;align-items:center;justify-content:center
}
.sb-tag-tree-row:hover .sb-tag-add-child{opacity:1}
.sb-tag-add-child:hover{background:#e0e0e0;color:#555}

/* ════════════════════════════
   IMAGE RESIZE TOOLBAR
════════════════════════════ */
#imgToolbar{
  position:fixed;background:#fff;border:1px solid #ddd;
  border-radius:8px;box-shadow:0 4px 18px rgba(0,0,0,.18);
  padding:8px 12px;display:flex;align-items:center;gap:8px;
  z-index:9998;font-size:.78rem;color:#444;
  transition:opacity .1s
}
#imgToolbar.hidden{display:none}
#imgToolbar label{color:#666;font-size:.75rem;white-space:nowrap}
#imgWidthIn{
  width:64px;border:1px solid #ddd;border-radius:4px;
  padding:3px 6px;font-size:.78rem;text-align:center
}
.img-toolbar-sep{width:1px;height:16px;background:#eee}
.img-toolbar-btn{
  padding:4px 8px;background:none;border:1px solid #e0e0e0;border-radius:4px;
  font-size:.73rem;cursor:pointer;color:#555;white-space:nowrap
}
.img-toolbar-btn:hover{background:#f0f0f0}
.img-toolbar-btn.img-btn-remove{color:#dc2626;border-color:#fca5a5}
.img-toolbar-btn.img-btn-remove:hover{background:#fff0f0}
#imgAlignBtns{display:flex;gap:4px}
/* Image size presets */
.img-preset-btn{
  padding:3px 7px;background:none;border:1px solid #e0e0e0;border-radius:4px;
  font-size:.72rem;cursor:pointer;color:#555;white-space:nowrap;font-weight:600
}
.img-preset-btn:hover{background:#f0f0f0;border-color:#aaa}

/* Pointer resize handle (shown when image selected) */
#imgResizeHandle{
  display:none;position:fixed;
  width:12px;height:12px;
  background:#1a73e8;border:2px solid #fff;border-radius:2px;
  cursor:se-resize;z-index:9999;
  box-shadow:0 1px 4px rgba(0,0,0,.4)
}

/* selected image highlight */
img.img-selected{
  outline:2px solid #1a73e8;outline-offset:2px;border-radius:2px
}

/* ════════════════════════════
   DRAG & DROP
════════════════════════════ */
.note-card[draggable="true"]{cursor:grab}
.note-card.dragging{opacity:.5;cursor:grabbing}
.sb-nb-item.nb-drag-over,.nb-card.nb-drag-over,.note-card.nb-drag-over{
  background:#d3e2fd!important;border:2px dashed #1a73e8;
  outline:none
}
.sb-tag-tree-row.nb-drag-over .sb-tag-tree-item{background:#d3e2fd;outline:2px dashed #1a73e8;outline-offset:-2px;border-radius:4px}
.drag-hint{
  font-size:.7rem;color:#6b7280;padding:2px 8px;
  position:absolute;bottom:2px;right:6px;pointer-events:none
}

/* ════════════════════════════
   MOVE TO NOTEBOOK MODAL
════════════════════════════ */
.move-note-list{max-height:280px;overflow-y:auto;border:1px solid #f0f0f0;border-radius:6px;margin:8px 0}
.move-note-list .dd-item{border-bottom:1px solid #f8f8f8}
.move-note-list .dd-item:last-child{border-bottom:none}

/* ════════════════════════════
   ARIA TREE FOCUS
════════════════════════════ */
[role="treeitem"]:focus{
  outline:2px solid #1a73e8;outline-offset:-1px;border-radius:4px
}
[role="treeitem"][aria-selected="true"] .sb-tag-tree-item{
  background:#d3e2fd;color:#1a73e8
}

/* ── Settings icon in sidebar logo ──────────────────────────────────────────── */
.sb-logo{display:flex;align-items:center;justify-content:space-between}
.sb-settings-btn{
  background:none;border:none;cursor:pointer;padding:3px;border-radius:4px;
  color:#6b7280;display:flex;align-items:center;flex-shrink:0
}
.sb-settings-btn:hover{background:#eee;color:#444}
.sb-settings-btn:focus-visible{outline:2px solid #1a73e8;outline-offset:1px}

/* ── Settings overlay ────────────────────────────────────────────────────────── */
.settings-overlay{
  position:fixed;inset:0;background:rgba(0,0,0,.45);
  display:flex;align-items:center;justify-content:center;
  z-index:1200
}
.settings-overlay.hidden{display:none}
.settings-panel{
  background:#fff;border-radius:10px;width:420px;max-width:calc(100vw - 32px);
  box-shadow:0 8px 32px rgba(0,0,0,.22);overflow:hidden
}
.settings-header{
  display:flex;align-items:center;justify-content:space-between;
  padding:16px 20px 12px;border-bottom:1px solid #e8e8e8
}
.settings-title{font-weight:600;font-size:.95rem;color:#222}
.settings-close{
  background:none;border:none;cursor:pointer;font-size:1rem;
  color:#6b7280;padding:4px 6px;border-radius:4px
}
.settings-close:hover{background:#f0f0f0;color:#333}
.settings-section{padding:20px}
.settings-section-title{font-weight:600;font-size:.82rem;color:#555;text-transform:uppercase;letter-spacing:.04em;margin-bottom:10px}
.settings-desc{font-size:.83rem;color:#666;line-height:1.55;margin:0 0 18px}
.settings-actions{display:flex;gap:10px;flex-wrap:wrap}
.settings-action-btn{
  display:inline-flex;align-items:center;gap:7px;
  padding:9px 18px;border-radius:6px;border:none;cursor:pointer;
  font-size:.85rem;font-weight:500;text-decoration:none
}
.settings-btn-primary{background:#1a73e8;color:#fff}
.settings-btn-primary:hover{background:#1558c0}
.settings-btn-secondary{background:#f1f3f4;color:#444;border:1px solid #ddd}
.settings-btn-secondary:hover{background:#e4e6e8}
.settings-status{
  margin-top:14px;font-size:.82rem;padding:7px 10px;border-radius:5px;display:none
}
.settings-status:not(:empty){display:block}
.settings-status-info{background:#e8f0fe;color:#1a73e8}
.settings-status-ok{background:#e6f4ea;color:#1e7e34}
.settings-status-err{background:#fce8e6;color:#c0392b}
.settings-status-warn{background:#fff8e1;color:#7b5800;border:1px solid #f9c500}

/* ── CONTEXT MENU ── */
.ctx-menu{
  position:fixed;z-index:9999;
  background:#fff;border:1px solid #d0d0d0;border-radius:6px;
  box-shadow:0 4px 16px rgba(0,0,0,.14);
  padding:4px 0;list-style:none;min-width:140px;
  font-size:13px;
}
.ctx-menu[hidden]{display:none}
.ctx-menu-item{
  display:flex;align-items:center;gap:8px;min-height:44px;box-sizing:border-box;
  padding:7px 14px;cursor:pointer;color:#222;
  white-space:nowrap;
}
.ctx-menu-item:hover{background:#f0f4ff}
.ctx-menu-item svg{flex-shrink:0;opacity:.65}
/* inline rename input inside sidebar items */
.sb-rename-input{
  flex:1;min-width:0;font:inherit;font-size:13px;
  border:none;border-bottom:1.5px solid #1a73e8;
  background:transparent;outline:none;padding:0 2px;
  color:inherit;
}

/* ════════════════════════════
   TAG PICKER MODAL
════════════════════════════ */
.tag-picker-modal{width:520px;max-width:95vw;max-height:80vh;display:flex;flex-direction:column}
.tag-picker-header{display:flex;align-items:center;justify-content:space-between;padding:18px 20px 6px}
.tag-picker-header h3{font-size:1rem;font-weight:700;margin:0}
.tag-picker-sub{font-size:.78rem;color:#6b7280;padding:0 20px 8px}
.tag-picker-chips{display:flex;flex-wrap:wrap;gap:5px;padding:0 20px 10px;min-height:10px}
.tag-picker-chip{
  display:flex;align-items:center;gap:5px;
  background:#e8f0fe;color:#1a73e8;
  font-size:.78rem;padding:3px 8px;border-radius:12px;
}
.tag-picker-chip button{background:none;border:none;cursor:pointer;color:#1a73e8;font-size:.8rem;padding:0 1px;line-height:1}
.tag-picker-chip button:hover{color:#c0392b}
.tag-picker-search-wrap{
  display:flex;align-items:center;gap:8px;
  margin:0 20px 6px;padding:7px 10px;
  border:1px solid #ddd;border-radius:6px;background:#fafafa;
}
.tag-picker-search-wrap input{flex:1;border:none;outline:none;font-size:.85rem;background:transparent}
.tag-picker-tree{flex:1;overflow-y:auto;border:1px solid #eee;border-radius:6px;margin:0 20px 14px;min-height:180px;max-height:320px}
.tp-row{display:flex;align-items:center;gap:4px;padding:5px 10px;cursor:pointer;user-select:none}
.tp-row:hover{background:#f5f5f5}
.tp-toggle{background:none;border:none;cursor:pointer;width:18px;font-size:.7rem;color:#6b7280;padding:0;flex-shrink:0}
.tp-cb{width:16px;height:16px;flex-shrink:0;cursor:pointer;accent-color:#1a73e8}
.tp-label{font-size:.83rem;flex:1}
.tp-count{font-size:.72rem;color:#6b7280;flex-shrink:0}
.tp-children{padding-left:22px}

/* ── PDF preview block ──────────────────────────────────────────────────────── */
.pdf-preview-block{
  border:1px solid #d0d7de;border-radius:6px;overflow:hidden;
  margin:10px 0;background:#fff;
}
.pdf-preview-header{
  display:flex;align-items:center;gap:8px;
  padding:6px 12px;background:#f6f8fa;
  border-bottom:1px solid #d0d7de;font-size:13px;
}
.pdf-icon{font-size:16px;flex-shrink:0}
.pdf-preview-name{
  flex:1;font-weight:500;overflow:hidden;
  text-overflow:ellipsis;white-space:nowrap;color:#24292f;
}
.pdf-download-btn{
  flex-shrink:0;color:#57606a;text-decoration:none;
  font-size:12px;padding:2px 8px;border-radius:4px;
  border:1px solid #d0d7de;background:#fff;white-space:nowrap;
}
.pdf-download-btn:hover{background:#f3f4f6;color:#24292f}
.pdf-preview-frame{
  width:100%;height:600px;border:none;display:block;
}

.legacy-table-markdown-block{
  border:1px solid #e5e7eb;border-radius:8px;background:#fafafa;
  padding:10px;margin:10px 0;
}
.legacy-table-actions{margin-bottom:8px}
.legacy-table-convert-btn{
  padding:6px 10px;border:1px solid #d0d7de;border-radius:6px;
  background:#fff;color:#1f2937;cursor:pointer;font-size:.8rem;
}
.legacy-table-convert-btn:hover{background:#f3f4f6}
.legacy-table-warning{
  margin-top:8px;padding:8px 10px;border-radius:6px;
  background:#fff4e5;color:#9a3412;font-size:.78rem;
}

.spreadsheet-block{
  border:1px solid #d0d7de;border-radius:8px;background:#fff;
  margin:10px 0;overflow:hidden;
}
.ss-header{
  display:flex;align-items:center;justify-content:space-between;gap:10px;
  padding:8px 12px;background:#f6f8fa;border-bottom:1px solid #d0d7de;
}
.ss-file-name{
  font-weight:600;color:#24292f;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
}
.ss-controls{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.ss-sheet-select{
  border:1px solid #d0d7de;border-radius:6px;background:#fff;
  padding:4px 8px;font-size:.78rem;color:#374151;
}
.ss-download-btn,.ss-collapse-btn{
  border:1px solid #d0d7de;border-radius:6px;background:#fff;
  color:#57606a;text-decoration:none;padding:4px 8px;font-size:.76rem;cursor:pointer;
}
.ss-download-btn:hover,.ss-collapse-btn:hover{background:#f3f4f6;color:#24292f}
.ss-loading,.ss-message{font-size:.78rem;color:#6b7280}
.ss-grid-wrap{
  overflow:auto;max-height:400px;background:#fff;
}
.ss-grid{
  width:max-content;min-width:100%;border-collapse:collapse;
  font-family:'Courier New',monospace;font-size:.76rem;
}
.ss-grid th,.ss-grid td{
  border:1px solid #e5e7eb;padding:4px 8px;white-space:nowrap;text-align:left;
}
.ss-grid .ss-row-num{
  text-align:right;color:#6b7280;background:#f9fafb;min-width:42px;
}
.ss-truncated-notice{
  padding:8px 12px;font-size:.76rem;color:#7c5c00;background:#fff8db;border-top:1px solid #f0e0a0;
}

.table-block{
  border:1px solid #d0d7de;border-radius:8px;background:#fff;
  margin:10px 0;padding:10px;
}
.table-toolbar{
  display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-bottom:8px;
}
.table-toolbar button,.table-toolbar select,.table-toolbar input{
  padding:5px 9px;border:1px solid #d0d7de;border-radius:6px;
  background:#fff;font-size:.78rem;color:#374151;
}
.table-toolbar button{cursor:pointer}
.table-toolbar button:hover{background:#f3f4f6}
.table-toolbar input{width:88px}
.tbl-caption-label{
  display:flex;align-items:center;gap:8px;margin-bottom:8px;
  font-size:.8rem;color:#4b5563;
}
.tbl-caption-input{
  flex:1 1 220px;min-width:180px;padding:6px 8px;border:1px solid #d0d7de;border-radius:6px;
}
.tbl-help{
  margin-bottom:8px;font-size:.74rem;color:#6b7280;
}
.tbl-scroll{overflow:auto;max-width:100%}
.tbl-edit{
  width:max-content;min-width:100%;border-collapse:collapse;font-size:.82rem;
}
.tbl-edit caption{
  caption-side:top;text-align:left;font-weight:600;color:#111827;padding-bottom:8px;
}
.tbl-edit th,.tbl-edit td{
  border:1px solid #d0d7de;padding:6px 8px;min-width:120px;background:#fff;vertical-align:top;
}
.tbl-edit th{background:#f8fafc;font-weight:600}
.tbl-edit th[contenteditable],.tbl-edit td[contenteditable]{outline:none}
.tbl-edit th[contenteditable]:focus,.tbl-edit td[contenteditable]:focus{
  box-shadow:inset 0 0 0 2px #1a73e8;background:#eef5ff;
}
.tbl-cell{white-space:pre-wrap;overflow-wrap:anywhere}
.tbl-nowrap{white-space:pre}
.tbl-align-left{text-align:left}
.tbl-align-center{text-align:center}
.tbl-align-right{text-align:right}
.tbl-cell-active{
  box-shadow:inset 0 0 0 2px #1a73e8;background:#eef5ff;
}
